00001
00022
00023
00024
00025 #include <net-snmp/net-snmp-config.h>
00026 #include <net-snmp/net-snmp-includes.h>
00027 #include <net-snmp/agent/net-snmp-agent-includes.h>
00028
00029
00030
00031
00032 #include "notification.h"
00033
00034
00035
00036
00037
00038 void
00039 init_notification(void)
00040 {
00041 DEBUGMSGTL(("example_notification",
00042 "initializing (setting callback alarm)\n"));
00043 snmp_alarm_register(30,
00044 SA_REPEAT,
00045 send_example_notification,
00046 NULL
00047 );
00048 }
00049
00077 void
00078 send_example_notification(unsigned int clientreg, void *clientarg)
00079 {
00080
00081
00082
00083
00084 oid notification_oid[] =
00085 { 1, 3, 6, 1, 4, 1, 8072, 2, 3, 0, 1 };
00086 size_t notification_oid_len = OID_LENGTH(notification_oid);
00087 static u_long count = 0;
00088
00089
00090
00091
00092
00093 oid objid_snmptrap[] = { 1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0 };
00094 size_t objid_snmptrap_len = OID_LENGTH(objid_snmptrap);
00095
00096
00097
00098
00099
00100
00101
00102 oid hbeat_rate_oid[] = { 1, 3, 6, 1, 4, 1, 8072, 2, 3, 2, 1, 0 };
00103 size_t hbeat_rate_oid_len = OID_LENGTH(hbeat_rate_oid);
00104 oid hbeat_name_oid[] = { 1, 3, 6, 1, 4, 1, 8072, 2, 3, 2, 2, 0 };
00105 size_t hbeat_name_oid_len = OID_LENGTH(hbeat_name_oid);
00106
00107
00108
00109
00110 netsnmp_variable_list *notification_vars = NULL;
00111 const char *heartbeat_name = "A girl named Maria";
00112 #ifdef RANDOM_HEARTBEAT
00113 int heartbeat_rate = rand() % 60;
00114 #else
00115 int heartbeat_rate = 30;
00116 #endif
00117
00118 DEBUGMSGTL(("example_notification", "defining the trap\n"));
00119
00120
00121
00122
00123 snmp_varlist_add_variable(¬ification_vars,
00124
00125
00126
00127 objid_snmptrap, objid_snmptrap_len,
00128
00129
00130
00131 ASN_OBJECT_ID,
00132
00133
00134
00135 (u_char *) notification_oid,
00136
00137
00138
00139 notification_oid_len * sizeof(oid));
00140
00141
00142
00143
00144
00145 snmp_varlist_add_variable(¬ification_vars,
00146 hbeat_rate_oid, hbeat_rate_oid_len,
00147 ASN_INTEGER,
00148 (u_char *)&heartbeat_rate,
00149 sizeof(heartbeat_rate));
00150
00151
00152
00153
00154 if (heartbeat_rate < 30 ) {
00155 snmp_varlist_add_variable(¬ification_vars,
00156 hbeat_name_oid, hbeat_name_oid_len,
00157 ASN_OCTET_STR,
00158 heartbeat_name, strlen(heartbeat_name));
00159 }
00160
00161
00162
00163
00164
00165
00166 ++count;
00167 DEBUGMSGTL(("example_notification", "sending trap %ld\n",count));
00168 send_v2trap(notification_vars);
00169
00170
00171
00172
00173 DEBUGMSGTL(("example_notification", "cleaning up\n"));
00174 snmp_free_varbind(notification_vars);
00175 }