| 1 |
|
| 2 |
#include <net-snmp/net-snmp-config.h> |
| 3 |
#include <net-snmp/net-snmp-includes.h> |
| 4 |
#include <net-snmp/agent/net-snmp-agent-includes.h> |
| 5 |
#include "mteScalars.h" |
| 6 |
#include "mteTrigger.h" |
| 7 |
|
| 8 |
/** Initializes the mteScalars module */ |
| 9 |
void |
| 10 |
init_mteScalars(void) |
| 11 |
{ |
| 12 |
static oid mteResource_oid[] = { 1, 3, 6, 1, 2, 1, 88, 1, 1 }; |
| 13 |
static oid mteTriggerFail_oid[] = { 1, 3, 6, 1, 2, 1, 88, 1, 2, 1 }; |
| 14 |
|
| 15 |
DEBUGMSGTL(("mteScalars", "Initializing\n")); |
| 16 |
|
| 17 |
netsnmp_register_scalar_group( |
| 18 |
netsnmp_create_handler_registration("mteResource", handle_mteResourceGroup, |
| 19 |
mteResource_oid, OID_LENGTH(mteResource_oid), |
| 20 |
HANDLER_CAN_RONLY), |
| 21 |
MTE_RESOURCE_SAMPLE_MINFREQ, MTE_RESOURCE_SAMPLE_LACKS); |
| 22 |
|
| 23 |
netsnmp_register_scalar( |
| 24 |
netsnmp_create_handler_registration("mteTriggerFailures", |
| 25 |
handle_mteTriggerFailures, |
| 26 |
mteTriggerFail_oid, OID_LENGTH(mteTriggerFail_oid), |
| 27 |
HANDLER_CAN_RONLY)); |
| 28 |
} |
| 29 |
|
| 30 |
int |
| 31 |
handle_mteResourceGroup(netsnmp_mib_handler *handler, |
| 32 |
netsnmp_handler_registration *reginfo, |
| 33 |
netsnmp_agent_request_info *reqinfo, |
| 34 |
netsnmp_request_info *requests) |
| 35 |
{ |
| 36 |
oid obj; |
| 37 |
long value = 0; |
| 38 |
|
| 39 |
switch (reqinfo->mode) { |
| 40 |
case MODE_GET: |
| 41 |
obj = requests->requestvb->name[ requests->requestvb->name_length-2 ]; |
| 42 |
switch (obj) { |
| 43 |
case MTE_RESOURCE_SAMPLE_MINFREQ: |
| 44 |
value = 1; /* Fixed minimum sample frequency */ |
| 45 |
snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, |
| 46 |
(u_char *)&value, sizeof(value)); |
| 47 |
break; |
| 48 |
|
| 49 |
case MTE_RESOURCE_SAMPLE_MAX_INST: |
| 50 |
value = 0; /* No fixed maximum */ |
| 51 |
snmp_set_var_typed_value(requests->requestvb, ASN_UNSIGNED, |
| 52 |
(u_char *)&value, sizeof(value)); |
| 53 |
break; |
| 54 |
|
| 55 |
case MTE_RESOURCE_SAMPLE_INSTANCES: |
| 56 |
#ifdef USING_DISMAN_EVENT_MTETRIGGER_MODULE |
| 57 |
value = mteTrigger_getNumEntries(0); |
| 58 |
#else |
| 59 |
value = 0; |
| 60 |
#endif |
| 61 |
snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, |
| 62 |
(u_char *)&value, sizeof(value)); |
| 63 |
break; |
| 64 |
|
| 65 |
case MTE_RESOURCE_SAMPLE_HIGH: |
| 66 |
#ifdef USING_DISMAN_EVENT_MTETRIGGER_MODULE |
| 67 |
value = mteTrigger_getNumEntries(1); |
| 68 |
#else |
| 69 |
value = 0; |
| 70 |
#endif |
| 71 |
snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE, |
| 72 |
(u_char *)&value, sizeof(value)); |
| 73 |
break; |
| 74 |
|
| 75 |
case MTE_RESOURCE_SAMPLE_LACKS: |
| 76 |
value = 0; /* mteResSampleInstMax not used */ |
| 77 |
snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, |
| 78 |
(u_char *)&value, sizeof(value)); |
| 79 |
break; |
| 80 |
|
| 81 |
default: |
| 82 |
snmp_log(LOG_ERR, |
| 83 |
"unknown object (%d) in handle_mteResourceGroup\n", (int)obj); |
| 84 |
return SNMP_ERR_GENERR; |
| 85 |
} |
| 86 |
break; |
| 87 |
|
| 88 |
default: |
| 89 |
/* |
| 90 |
* Although mteResourceSampleMinimum and mteResourceSampleInstanceMaximum |
| 91 |
* are defined with MAX-ACCESS read-write, this version hardcodes |
| 92 |
* these values, so doesn't need to implement write access. |
| 93 |
*/ |
| 94 |
snmp_log(LOG_ERR, |
| 95 |
"unknown mode (%d) in handle_mteResourceGroup\n", |
| 96 |
reqinfo->mode); |
| 97 |
return SNMP_ERR_GENERR; |
| 98 |
} |
| 99 |
|
| 100 |
return SNMP_ERR_NOERROR; |
| 101 |
} |
| 102 |
|
| 103 |
int |
| 104 |
handle_mteTriggerFailures(netsnmp_mib_handler *handler, |
| 105 |
netsnmp_handler_registration *reginfo, |
| 106 |
netsnmp_agent_request_info *reqinfo, |
| 107 |
netsnmp_request_info *requests) |
| 108 |
{ |
| 109 |
#ifndef USING_DISMAN_EVENT_MTETRIGGER_MODULE |
| 110 |
long mteTriggerFailures = 0; |
| 111 |
#endif |
| 112 |
|
| 113 |
switch (reqinfo->mode) { |
| 114 |
case MODE_GET: |
| 115 |
snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, |
| 116 |
(u_char *)&mteTriggerFailures, |
| 117 |
sizeof(mteTriggerFailures)); |
| 118 |
break; |
| 119 |
|
| 120 |
|
| 121 |
default: |
| 122 |
/* |
| 123 |
* we should never get here, so this is a really bad error |
| 124 |
*/ |
| 125 |
snmp_log(LOG_ERR, |
| 126 |
"unknown mode (%d) in handle_mteTriggerFailures\n", |
| 127 |
reqinfo->mode); |
| 128 |
return SNMP_ERR_GENERR; |
| 129 |
} |
| 130 |
|
| 131 |
return SNMP_ERR_NOERROR; |
| 132 |
} |
| 133 |
|