AgentXcpp  Version:0.3
Internals Documentation
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Pages
helpers.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Tanjeff-Nicolai Moos <tanjeff@cccmz.de>
3  *
4  * This file is part of the agentXcpp library.
5  *
6  * AgentXcpp is free software: you can redistribute it and/or modify
7  * it under the terms of the AgentXcpp library license, version 1, which
8  * consists of the GNU General Public License and some additional
9  * permissions.
10  *
11  * AgentXcpp is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * See the AgentXcpp library license in the LICENSE file of this package
17  * for more details.
18  */
19 #include <QDateTime>
20 
21 #include "helpers.hpp"
22 
23 using namespace agentxcpp;
24 
25 namespace agentxcpp
26 {
27  /**
28  * \internal
29  *
30  * \brief Variable to measure the uptime of the current process.
31  *
32  * This variable is initialized when the executable starts up
33  * and holds the time at which this happened. Afterwards,
34  * the uptime of the process can be calculated.
35  */
36  static QDateTime process_start_time(QDateTime::currentDateTime());
37 }
38 
40  {
41  // Calculate uptime
42  qint64 uptime = process_start_time.msecsTo(QDateTime::currentDateTime());
43 
44  // Convert uptime to hundreths of seconds
45  TimeTicksVariable sysuptime( uptime/10 );
46 
47  // Return result
48  return sysuptime;
49  }
50 
52  quint32 specific_trap)
53  {
54  // We need the OID of the SNMPv1 traps. These are defined here.
55  //
56  // First we define a "helper" OID:
57  static const Oid snmpTraps_oid(snmpMIBObjects_oid, "5");
58  //
59  // Some traps according to RFC 1907:
60  static const Oid snmpTraps_coldStart_oid(snmpTraps_oid, "1");
61  static const Oid snmpTraps_warmStart_oid(snmpTraps_oid, "2");
62  static const Oid snmpTraps_authenticationFailure_oid(snmpTraps_oid, "5");
63  //
64  // Some traps according to RFC 1573:
65  static const Oid snmpTraps_linkDown_oid(snmpTraps_oid, "3");
66  static const Oid snmpTraps_linkUp_oid(snmpTraps_oid, "4");
67 
68  // Finally, egpNeighborLoss. According to RC 1907 it is defined in RFC
69  // 1213, however, the latter doesn't define it. On the other hand,
70  // RFC 2089 defines egpNeighborLoss as 1.3.6.1.6.3.1.1.5.6, which is
71  // snmpTraps.6 and corresponds to the comment in RFC 1907, so we use this
72  // one:
73  static const Oid snmpTraps_egpNeighborLoss_oid(snmpTraps_oid, "6");
74 
75  // calculate the value of snmpTrapOID.0 according to RFC 1908:
76  Oid value;
77 
78  switch(generic_trap)
79  {
80  case coldStart:
81  value = snmpTraps_coldStart_oid;
82  break;
83  case warmStart:
84  value = snmpTraps_warmStart_oid;
85  break;
86  case linkDown:
87  value = snmpTraps_linkDown_oid;
88  break;
89  case linkUp:
90  value = snmpTraps_linkUp_oid;
91  break;
93  value = snmpTraps_authenticationFailure_oid;
94  break;
95  case egpNeighborLoss:
96  value = snmpTraps_egpNeighborLoss_oid;
97  break;
98  case enterpriseSpecific:
99  value = enterprises_oid;
100  value.push_back(0);
101  value.push_back(specific_trap);
102  break;
103  default:
104  // invalid generic_trap value!
105  throw(inval_param());
106  }
107 
108  // Create and return varbind
109  return value;
110  }
Represents an SNMP object identifier (OID).
Definition: Oid.hpp:91
generic_trap_t
The allowed values for specific-trap (SNMPv1 trap).
Definition: helpers.hpp:51
Exception for invalid parameter.
Definition: exceptions.hpp:36
Oid generate_v1_snmpTrapOID(generic_trap_t generic_trap, quint32 specific_trap=0)
Create snmpTrapOID.0 value from SNMPv1 trap data.
Definition: helpers.cpp:51
TimeTicksVariable processUpTime()
Calculate the uptime of the current process.
Definition: helpers.cpp:39
Represents a TimeTicks as described in RFC 2741.