/* * checkpris - Check up/down status of PRIs on Ascend MAX and 3COM * HiperDSP cards * * VERSION 1.0.1 - Nov 22, 2000 * */ #include #include #include #include #include #include #include /* START OF USER DEFINABLE SETTINGS */ /* Below are all the definitions that you will need to modify */ /* that usually dont change. Rest of them are in the config file */ /* Path to data file */ #define DATAFILE "/etc/checkpris.cfg" /* Directory where status data files will get stored for checking */ /* Filename format: DATADIR/.pri--.dat */ #define DATADIR "/tmp" /* File to log info/errors to */ #define LOGFILE "/tmp/.checkpris.log" /* Path to the sendmail program to send out notifications */ #define PATHTO "/usr/sbin/sendmail -t" /* OID for operational status of Ascend MAX T1 Span */ #define LINESTATE_OID_M "interfaces.ifTable.ifEntry.ifOperStatus.%d" /* OID for operational status of 3COM T1 Span, interfaces are */ /* 025 as in slot 1 is interface 1025, 2 is 2025, 10 is 10025 */ #define LINESTATE_OID_3 ".1.3.6.1.2.1.10.18.6.1.10.%d" /* OIDs for yellow alarm and red alarm state of 3com Netserver type PRIs */ /* State of 1 means NO alarm. Interfaces are 100 as in span 1 is */ /* 1001 */ #define LINESTATE_OID_NETSRV_YELLOW ".1.3.6.1.3.2.1.1.9.%d" #define LINESTATE_OID_NETSRV_RED ".1.3.6.1.3.2.1.1.10.%d" /* Program to get snmp requests */ #define SNMP_PROG "/usr/bin/snmpget" /* Read SNMP community of chassises we are checking */ #define READ_COMM "public" /* Who do we set the from address to in an email or page? */ #define FROM "nobody@yourdomain.com" /* Who to page. Normally an email address that pages an admin via modem */ /* this goes along with P_SUBJECT which I set to blank for paging */ /* Set this to nothing to disable */ #define PAGETO "admin-pager@yourdomain.com" /* First person to email notification with a subject of M_SUBJECT */ /* Set this to nothing to disable */ #define MAILTO1 "admin@yourdomain.com" /* Second person to email notification with a subject of M_SUBJECT */ /* Set this to nothing to disable */ #define MAILTO2 "admin2@yourdomain.com" /* Subject of page, if you want one */ #define P_SUBJECT "" /* Subject of email, if you want one */ #define M_SUBJECT "PRI STATUS" /* Print debugging info? 1 for yes, 0 for no */ #define DEBUG 0 /* END OF USER DEFINABLE SETTINGS */ void wlog(char *str); void remove_first_comma(char *inpstr); void notify_admin(char *host, char *desc, char *type, int port, char *status); void midcpy(char *strf, char *strt, int fr, int to); void remove_first(char *inpstr); void strtolower(char *str); char mess[500]; int main(void) { int i=0,j=0,z=0; int wanport[14]; char hostname[50]; char hostdesc[50]; char hosttype[50]; char temp[3]; char oid[256]; char junk1[100]; char junk2[100]; char junk3[100]; char junk4[100]; char line[257]; char wanline[257]; char command[256]; char filename[256]; FILE *fp; FILE *fp2; FILE *pp; hostname[0]=0; wanport[0]=0; wanport[1]=0; wanport[2]=0; wanport[3]=0; wanport[4]=0; wanport[5]=0; wanport[6]=0; wanport[7]=0; wanport[8]=0; wanport[9]=0; wanport[10]=0; wanport[11]=0; wanport[12]=0; wanport[13]=0; line[0]=0; if (!(fp=fopen(DATAFILE,"r"))) { sprintf(mess,"Can't open checkpri data file %s to get list!\n",DATAFILE); printf("%s",mess); wlog(mess); sprintf(mess,"ERRNO: %s (%d)\n",strerror(errno),errno); printf("%s",mess); wlog(mess); exit(0); } while (fgets(line,256,fp) != NULL) { line[strlen(line)-1]=0; if (line[0]=='#' || line[0]==' ' || !strlen(line)) continue; sscanf(line,"%s ",hostname); remove_first(line); sscanf(line,"%s ",hostdesc); remove_first(line); sscanf(line,"%s ",hosttype); remove_first(line); sscanf(line,"%s ",wanline); if (DEBUG==1) { printf("Hostname: %s\nDesc: %s\nType: %s\nWanline: %s\n", hostname,hostdesc,hosttype,wanline); } if (strstr(wanline,",")) { for (i=0;i