/*! This function: * * 1) Registers itself with the Master Agent * 2) Initializes all of the SNMPStats modules scalars and tables, while * simultaneously registering their respective SNMP OID's and handlers * with the master agent. * 3) Repeatedly checks for new SNMP messages to process * * \note This function never returns, so it should always be called from a * sub-process. */ static int initialize_agentx(void) { /* We register with a master agent */ register_with_master_agent(AGENT_PROCESS_NAME); LM_DBG("Initializing Kamailio OID's for SNMPD MasterX\n"); /* Initialize all scalars, and let the master agent know we want to * handle all OID's pertaining to these scalars. */ init_kamailioSIPCommonObjects(); init_kamailioSIPServerObjects(); init_kamailioObjects(); /* Initialiaze all the tables, and let the master agent know we want to * handle all the OID's pertaining to these tables */ init_kamailioSIPPortTable(); init_kamailioSIPMethodSupportedTable(); init_kamailioSIPStatusCodesTable(); init_kamailioSIPRegUserTable(); init_kamailioSIPContactTable(); init_kamailioSIPRegUserLookupTable(); init_kamailioServer(); init_kamailioNet(); init_kamailioNetConfig(); LM_DBG("Done initializing Kamailio OID's for SNMPD MasterX\n"); /* In case we recevie a request to stop (kill -TERM or kill -INT) */ keep_running = 1; while(keep_running) { /* update the local config framework structures */ cfg_update(); agent_check_and_process(1); /* 0 == don't block */ } LM_DBG("Shutting down Kamailio SNMPD MasterX sub agent.\n"); snmp_shutdown(AGENT_PROCESS_NAME); SOCK_CLEANUP; exit (0); return 0; }
/* This function will be called periodically from an OpenSIPS timer. The first * time it is called, it will query OPENSER-MIB for configured thresholds. */ void run_alarm_check(unsigned int ticks, void * attr) { static int msg_queue_minor_threshold; static int msg_queue_major_threshold; static int dialog_minor_threshold; static int dialog_major_threshold; static char firstRun = 1; int bytesInMsgQueue; int numActiveDialogs; /* We only need to retrieve our thresholds the first time around */ if (firstRun) { register_with_master_agent(ALARM_AGENT_NAME); msg_queue_minor_threshold = get_msg_queue_minor_threshold(); msg_queue_major_threshold = get_msg_queue_major_threshold(); dialog_minor_threshold = get_dialog_minor_threshold(); dialog_major_threshold = get_dialog_major_threshold(); firstRun = 0; } /* We need to have this here in case the master agent fails and is * restarted. Without it, we won't be able to re-establish or AgentX * connection */ agent_check_and_process(0); /* Check for MsgQueue alarm conditions */ /* The retrieved number of bytes will be zero unless * there is an alarm condition. In this case the number * of bytes will be returned. */ bytesInMsgQueue = check_msg_queue_alarm(msg_queue_minor_threshold); if (bytesInMsgQueue != 0) { send_openserMsgQueueDepthMinorEvent_trap(bytesInMsgQueue, msg_queue_minor_threshold); } bytesInMsgQueue = check_msg_queue_alarm(msg_queue_major_threshold); if (bytesInMsgQueue != 0) { send_openserMsgQueueDepthMajorEvent_trap(bytesInMsgQueue, msg_queue_major_threshold); } /* Check for Dialog alarm conditions: */ numActiveDialogs = check_dialog_alarm(dialog_minor_threshold); if (numActiveDialogs != 0) { send_openserDialogLimitMinorEvent_trap(numActiveDialogs, dialog_minor_threshold); } numActiveDialogs = check_dialog_alarm(dialog_major_threshold); if (numActiveDialogs != 0) { send_openserDialogLimitMajorEvent_trap(numActiveDialogs, dialog_major_threshold); } }