/*
*
* U.S. Government Rights - Commercial software. Government users are subject to
* the Sun Microsystems, Inc. standard license agreement and applicable
* provisions of the FAR and its supplements.
*
*
* This distribution may include materials developed by third parties. Sun, Sun
* Microsystems, the Sun logo and Solaris are trademarks or registered
* trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
*
*/
/*
* demo_module_4:
*
* This module is based on the SDK-DEMO4-MIB.txt MIB. It implements the
* me4LoadGroup objects.
*
* This example module demonstrates following features: - Automatic Refresh of
* data in regular intervals - Check for alarm condition in regular intervals
* and generate trap if necessary. - Read threshold values from an external
* configuration file called demo_module_4.conf
*/
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include "me4LoadGroup.h"
#include <netdb.h>
/*
* Data for demo_module_4: loadavg1 stores data for me4SystemLoadAvg1min
* loadavg5 stores data for me4SystemLoadAvg5min loadavg15 stores data for
* me4SystemLoadAvg15min
*/
/* Alarm thresholds for demo_module_4 */
/* Maintain previous alarm states for comparison */
/* Common variables for information to be included in traps */
/** Initializes the demo_module_4 module
* This is the Init function which is called when the module is loaded by the agent.
*
* Note: The name of this function has been changed from "init_me4LoadGroup" to
* "init_demo_module_4" to give unique names to example modules across the SMA
* SDK.
*/
void
init_demo_module_4(void)
{
int retCode;
("me4SystemLoadAvg15min",
("me4SystemLoadAvg1min",
("me4SystemLoadAvg5min",
/* Initialize some common data */
if (retCode != 0)
/* Allocate memory once. These variables will hold load data */
/*
* Register for thresholds. When a token (say threshold_loadavg1) is
* found in demo_module_4.conf file, the read_load_thresholds function is
* called by the agent
*/
}
/**
* The callback function that is called after the configuration files are
* read by the agent ( the thresholds are loaded into the module )
*/
int
demo_4_post_read_config(int a, int b, void *c, void *d)
{
/* Refresh the load data every 60 seconds */
/* Acquire the data first time */
refreshLoadAvg(0, NULL);
return 1;
}
/*
* This function is generated by mib2c. It is called when an SNMP "get"
* request arrives for the node me4SystemLoadAvg15min
*
*/
int
{
/*
* We are never called for a GETNEXT if it's registered as a "instance",
* as it's "magically" handled for us.
*/
/*
* a instance handler also only hands us one request at a time, so we
* don't need to loop over a list of requests; we'll only get one.
*/
/* Refresh the load data by calling the refresh function */
refreshLoadAvg(0, NULL);
case MODE_GET:
refreshLoadAvg(0, NULL);
snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, (u_char *) loadavg15, strlen(loadavg15));
break;
default:
/* we should never get here, so this is a really bad error */
return SNMP_ERR_GENERR;
}
return SNMP_ERR_NOERROR;
}
/*
* This function is generated by mib2c. It is called when an SNMP "get"
* request arrives for the node me4SystemLoadAvg1min
*
*/
int
{
/*
* We are never called for a GETNEXT if it's registered as a "instance",
* as it's "magically" handled for us.
*/
/*
* a instance handler also only hands us one request at a time, so we
* don't need to loop over a list of requests; we'll only get one.
*/
case MODE_GET:
refreshLoadAvg(0, NULL);
snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, (u_char *) loadavg1, strlen(loadavg1));
break;
default:
/* we should never get here, so this is a really bad error */
return SNMP_ERR_GENERR;
}
return SNMP_ERR_NOERROR;
}
/*
* This function is generated by mib2c. It is called when an SNMP "get"
* request arrives for the node me4SystemLoadAvg5min
*
*/
int
{
/*
* We are never called for a GETNEXT if it's registered as a "instance",
* as it's "magically" handled for us.
*/
/*
* a instance handler also only hands us one request at a time, so we
* don't need to loop over a list of requests; we'll only get one.
*/
refreshLoadAvg(0, NULL);
case MODE_GET:
refreshLoadAvg(0, NULL);
snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, (u_char *) loadavg5, strlen(loadavg5));
break;
default:
/* we should never get here, so this is a really bad error */
return SNMP_ERR_GENERR;
}
return SNMP_ERR_NOERROR;
}
/*
* refreshLoadAvg: This is the function which "refreshes" the load data using
* the system call "getloadavg". The data is stored in the 3 variables
* loadavg1, loadavg5, loadavg15. Once the data is refreshed, the "check"
* functions are called to check for alarm conditions
*/
void
{
}
/*
* Function: conv_alarm_state : This function returns appropriate charecter
* string for each integer alarm type
*/
char *
{
switch (state) {
case 0:
return "OK\0";
case 1:
return "ERROR\0";
default:
return "NULL\0";
}
}
/*
* read_load_thresholds: This function is called when a registered token (see
* Init_demo_module_4 function) is found in the appropriate configuration
* file. The token's values (thresholds) are then stored in some variables.
*/
void
{
} else {
/* Do nothing */
}
return;
}
/* send_trap: This function generates an snmpv2 trap */
void
send_trap(u_char * hostname, u_char * modulename, oid * trapoid, int size, u_char * status, u_char * description)
{
/* This is the notification type itself. This is statusChange trap */
/*
* In the notification, we have to assign our notification OID to the
* snmpTrapOID.0 object. Here is it's definition.
*/
/*
* here is where we store the variables to be sent in the trap
*/
/*
* add in the trap definition object
*/
/*
* the snmpTrapOID.0 variable
*/
/*
* value type is an OID
*/
/*
* value contents is our notification OID
*/
(u_char *) notification_oid,
/*
* size in bytes = oid length * sizeof(oid)
*/
notification_oid_len * sizeof(oid));
/*
* if we wanted to insert additional objects, we'd do it here
*/
/*
* value type is an OID
*/
/*
* value contents is our notification OID
*/
/*
* size in bytes = oid length * sizeof(oid)
*/
/*
* value type is an OID
*/
/*
* value contents is our notification OID
*/
(u_char *) modulename,
/*
* size in bytes = oid length * sizeof(oid)
*/
strlen((char *) modulename));
/*
* value type is an OID
*/
/*
* value contents is our notification OID
*/
/*
* size in bytes = oid length * sizeof(oid)
*/
/*
* value type is an OID
*/
/*
* value contents is our notification OID
*/
/*
* size in bytes = oid length * sizeof(oid)
*/
/*
* value type is an OID
*/
/*
* value contents is our notification OID
*/
(u_char *) description,
/*
* size in bytes = oid length * sizeof(oid)
*/
strlen((char *) description));
/* SEND THE TRAP !!!! */
/*
* free the created notification variable list
*/
return;
}
/*
* check_loadavg1_state: This function does 2 things: step-1) Determine the
* current alarm state of the node by comparing it's value with threshold.
* step-2) Depending on the new state of the node, generate a trap
*/
void
{
/* Trap stuff */
int size;
/* Step-1 */
/* If threshold is crossed, set state to ERROR */
if (currentLoad > threshold_loadavg1) {
}
/* Step-2 */
/* Depending on the new state, send trap if necessary */
if (new_loadavg1_state > prev_loadavg1_state) {
/* Send trap */
} else if (new_loadavg1_state == prev_loadavg1_state) {
/* No Change in state .. Do nothing */
} else if (new_loadavg1_state < prev_loadavg1_state) {
if (new_loadavg1_state == OK) {
/* Send OK trap */
}
}
}
/*
* check_loadavg5_state: This function does 2 things: step-1) Determine the
* current alarm state of the node by comparing it's value with threshold.
* step-2) Depending on the new state of the node, generate a trap
*/
void
{
/* Trap stuff */
int size;
/* If threshold is crossed, set state to ERROR */
if (currentLoad > threshold_loadavg5)
/* Depending on the new state, send trap if necessary */
if (new_loadavg5_state > prev_loadavg5_state) {
/* Send trap */
} else if (new_loadavg5_state == prev_loadavg5_state) {
/* No Change in state .. Do nothing */
} else if (new_loadavg5_state < prev_loadavg5_state) {
if (new_loadavg5_state == OK) {
/* Send OK trap */
}
}
}
/*
* check_loadavg15_state: This function does 2 things: step-1) Determine the
* current alarm state of the node by comparing it's value with threshold.
* step-2) Depending on the new state of the node, generate a trap
*/
void
{
/* Trap stuff */
int size;
/* If threshold is crossed, set state to ERROR */
if (currentLoad > threshold_loadavg15)
/* Depending on the new state, send trap if necessary */
if (new_loadavg15_state > prev_loadavg15_state) {
/* Send trap */
} else if (new_loadavg15_state == prev_loadavg15_state) {
/* No Change in state .. Do nothing */
} else if (new_loadavg15_state < prev_loadavg15_state) {
if (new_loadavg15_state == OK) {
/* Send OK trap */
}
}
}