#include "nagios_common_snmp.h" #define SCRIPT_VERSION 0.5 #define TMP_FILE_NAME_PREFIX "tmp_Nagios_proc." /* default delta for averages : 300s = 5min */ #define DEFAULT_DELTA_AVERAGE 300 /******************************** help & usage ********************************/ char usage[]= "-A [-W]"; /******************************** SNMP data ********************************/ oid ipRouteAge[]={1,3,6,1,2,1,4,21,1,10}; oid ipRouteDest[]={1,3,6,1,2,1,4,21,1,1}; void print_usage() { printf("Usage: %s %s %s\n",plugin_name, common_usage, usage); exit(N_UNKNOWN); } void print_version() { printf("%s version %.2f / Package version %.2f\n",plugin_name,SCRIPT_VERSION,NAGIOS_SNMP_VERSION); exit(N_UNKNOWN); } void print_help(){ printf(_("\nSNMP Process Monitor for Nagios version %.2f\n"),SCRIPT_VERSION); printf(_("Nagios SNMP plugins version %.2f, GPL licence, (c)2004-2007 Patrick Proy\n\n"),NAGIOS_SNMP_VERSION); printf("Usage: %s %s %s\n",plugin_name, common_usage, usage); DEFAULT_HELP_PRINT printf("-A, --minage=MIN\n"); printf(_(" Minimum age of route entries\n")); printf("-W, --warn\n"); printf(_(" Return WARNING state instead of CRITICAL\n")); exit(N_UNKNOWN); } /******************************** Main of check_snmp_process ********************************/ int main(int argc, char ** argv) { /* limits */ int n_maxOID=500; int max_changes=10; /* OID array */ oid valOID[n_maxOID][MAX_OID_LEN]; size_t valOID_len[n_maxOID]; int n_valOID; int index_match,index2_match; snmp_table *proc_index[n_maxOID]; int ERROR_STATE=N_CRITICAL; /* result tables */ snmp_table *route_age,*route_dest,*tempT,*valueT,*paramT,*temp2T, *temp3T; /* counters, output, etc... */ char buffer[100]=""; int i,j; char *buff_select; int num_proc,test_int,num_proc_ok; int final_status; float res_memory; int res_cpu; /* file datas & name */ unsigned long long int file_values[MAX_ROWS][MAX_ITEMS]; /* to get & store data in file */ int rows=0;int items=0;int file_ret,found_data; char base_file_name[MAX_FILE_LENGTH]=BASE_DIR; char file_name[MAX_FILE_LENGTH]; long unsigned int timenow,trigger,trigger_low; float found_value; /************ Options ******************/ int o_minage=1800; /* */ int o_warn=0; /***************** options init ********************/ options_nagsnmp liste[] = { COMMON_OPTIONS /*********** Specific for the script ***************/ /* { type ,short , o_long , present,ivalue, cvalue, int_value n_array} */ {0, 'W', "warn", 0, NULL, NULL, &o_warn, 0}, /* 12 */ {1, 'A', "minage", 0, NULL, NULL, &o_minage, 0} /*13*/ }; int n_liste=COMOPTNUM+2; /* Initialise gettext and other parameters */ if (init_plugins_gettext()!=0) { printf("Cannot initialize GETTEXT\n"); return N_UNKNOWN;} strcpy(plugin_name,"check_snmp_routetable_stable"); /* Plugin name for cache */ strcpy(plugin_tmp_prefix,TMP_FILE_NAME_PREFIX); /***************** options init ********************/ init_options(); if (get_options (argc, argv,liste,n_liste)!=0) print_usage(); i=check_common_options(); if (i==1) print_usage(); else if (i==2) print_help(); else if (i==3) print_version() ; /***************** check options *****************/ if(o_warn!=0) { ERROR_STATE=N_WARNING; } /**************** open snmp session ******************/ if (init_snmp_session()!=0) { printf(_("Error opening SNMP session : %s\n"),error); free(error); return N_UNKNOWN; } /***************** Get name or path table *****************/ route_age=get_snmp_table (ss,ipRouteAge, sizeof (ipRouteAge) / sizeof (oid),snmp_bulk,&error); if (route_age==NULL) { printf(_("Error reading table routeAge: %s\n"),error); free(error); return N_UNKNOWN; } route_dest=get_snmp_table (ss,ipRouteDest, sizeof (ipRouteDest) / sizeof (oid),snmp_bulk,&error); if (route_dest==NULL) { printf(_("Error reading table routeDest: %s\n"),error); free(error); return N_UNKNOWN; } /**************** parse results ******************/ tempT=route_age; sprintf(buffer,"Routing table entries stable."); while((tempT!=NULL)&&(max_changes>0)) { //printf("Value %i\n",tempT->value_l); if(tempT->value_lnext; } strcat_output(buffer); if (final_status==N_CRITICAL) { print_output_with_status(N_CRITICAL); return N_CRITICAL; } if (final_status==N_WARNING) { print_output_with_status(N_WARNING); return N_WARNING; } if (final_status==N_UNKNOWN) { print_output_with_status(N_UNKNOWN); return N_UNKNOWN; } print_output_with_status(N_OK); return N_OK; }