Execution: Sbc_calls_status_new auto_ssh_sbc_10_17.sh | auto_ssh_sbc_11_17.sh
VI sbc_calls_status_new.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #define OK 0#define WARNING 1#define CRITICAL 2#define UNKNOWN 3#define LEN 1000#define min_len 20#define short_time 1//Unit of Minute#def INE long_time 10//Unit of minute//#define TCL_CMD "/home/weihu/tcl/" #define Tcl_cmd "/usr/local/nagios/libexec/" # Define Sbc_gg_short_time_file "/usr/local/nagios/libexec/sbc_gg_call_short_time_file.tmp" #define SBC_YZ_SHORT_ Time_file "/usr/local/nagios/libexec/sbc_yz_call_short_time_file.tmp"//#define SBC_SHORT_TIME_FILE "/home/tssp/ Sbc/sbc_call_short_time_file.tmp "#define Sbc_gg_long_time_file"/usr/local/nagios/libexec/sbc_gg_call_long_time_ File.tmp "#define Sbc_yz_long_time_file"/usr/local/nagios/libexec/sbc_yz_call_long_time_file.tmp "//#define SBC_ Long_time_file "/home/tssp/sbc/sbc_call_long_time_file.tmp" int exitstatus=ok;char *exit_status[4]={"OK", "WARNING" , "CRITICAL", "UNKNOWN"};char Status_information[len];char Performance_data[len];//char Sbc_gg_old_value[min_len]={0};//char sbc_yz_old_value[min_len]={0};int read_time_file (int minute,char *file) {int Ret File *fp;char *ch;char readbuf[20]={0};int now_minute=0;//fp=fopen (file, "A +"); Fp=fopen (file, "r+"); if (fp==null) { fprintf (stderr, "fopen () error.\n"); return-1;} Ch=fgets (READBUF,20,FP); if (ch==null) {fprintf (stderr, "fgets () error.\n");//return-1;} printf ("readbuf=%s\n", Readbuf), Now_minute=atoi (readbuf);p rintf ("now_minute=%d\n", Now_minute); if (!STRCMP ( Readbuf, "")) {if (minute==short_time) {if (now_minute<short_time-1) {exitstatus=warning;} else if (now_minute>=short_time-1) {exitstatus=critical;}} else if (minute==long_time) {/*if (now_minute<long_time-1) {exitstatus=warning;} else if (now_minute>=long_time-1) {*/if (now_minute>=long_time-1) {exitstatus=critical;}} fprintf (FP, "%s", "1");p rintf ("file is null,value=1\n");} else {if (minute==short_time) {if (now_minute<short_time-1) {Exitstatus=warning;ret=fseek (fp,0,seek_set); fprintf (FP, "%d", ++now_minute);/*fclose (FP); Fp=foPen (file, "w+"); fprintf (FP, "%d", now_minute++); */}else if (now_minute>=short_time-1) {exitstatus=critical;ret= Fseek (Fp,0,seek_set); fprintf (FP, "%d", ++now_minute);}} else if (minute==long_time) {if (now_minute<long_time-1) {//exitstatus=warning;exitstatus=ok;ret=fseek (Fp,0,SEEK _set); fprintf (FP, "%d", ++now_minute);} else if (now_minute>=long_time-1) {//if (now_minute>=long_time-1) {Exitstatus=critical;ret=fseek (fp,0,SEEK_ SET); fprintf (FP, "%d", ++now_minute);}}} Ret=fclose (FP); if (ret!=0) {fprintf (stderr, "fclose () error.\n"); return-1;} return 0;} int Parse_cmd (char *sh_cmd,char *active_count,char *high_count,char *total_count) {int ret; FILE *FP; Char Tmpbuf[len]; Char Readbuf[len]; Char *p,*str;int i=0;int line=0;int mark1=0;int mark2=0;//fp=popen ("/home/neo/check_log/tcl/auto_ssh.sh", "R"); Fp=popen (Sh_cmd, "R"); if (fp==null) {fprintf (stderr, "Popen () error. "); exitstatus=critical; printf ("%s:-%s | %s\n ", Exit_status[exitstatus],status_information,performance_data); Exit (Exitstatus); } while (Fgets (READBUF,LEN,FP)!=null) {//line++;if (Strstr (Readbuf, "SIP Sessions")) {memset (Tmpbuf,0,len); strcpy (tmp BUF,READBUF);//printf ("%s", Tmpbuf), for (P=strtok (Tmpbuf, "");p; P=strtok (NULL, ""), i++) {if (i==2) {//printf ("%s\n", p ); strcpy (active_count,p);} if (i==3) {//printf ("%s\n", p); strcpy (high_count,p);} if (i==4) {//printf ("%s\n", p); strcpy (total_count,p); break;}}} if (i==4) {break;} /*line++;//printf ("line=%d,readbuf=%s", Line,readbuf), if (line==3) {for (P=strtok (Readbuf, "");p; P=strtok (NULL, "")) {//Str=p;//sunmark1++;if (mark1==2) {//printf ("p=%s\n", p); strcpy (active_status,p);//printf ("active_status=%s\n", active_status);}}} if (line==4) {for (P=strtok (Readbuf, "");p; P=strtok (NULL, "/") {mark2++;if (mark2==2) {//printf ("p=%s\n", p); strcpy ( ACTIVE_IP_ADDR,P);//printf ("active_ip_addr=%s\n", Active_ip_addr);}} break;} */} ret=fclose (FP); if (fp==null) { fprintf (stderr, "Popen () error.\n"); return-1; }return 0;} int main (int argc, char *argv[]) {int ret;int Hour;char Str_hour[len];char Sh_cmd[len];char Active_count[len];char High_count[len];char Total_count[len];char active_ip_addr[len];time_t timestamp;struct TM *TP; FILE *fp;if (argc<=1) {printf ("%s%s\n", argv[0], "auto_ssh_sbc_10_17.sh | auto_ssh_sbc_11_17.sh"); exit (-1);} Timestamp=time (NULL); Tp=localtime (Xtamp); sprintf (Str_hour, "%d", Tp->tm_hour)//sprintf (Str_hour, "%d", 3); hour =atoi (Str_hour);//printf ("hour=%d\n", Hour), sprintf (Sh_cmd, "%s%s", tcl_cmd,argv[1]);//printf ("sh_cmd=%s\n", Sh_ CMD); Ret=parse_cmd (Sh_cmd,active_count,high_count,total_count); if (ret!=0) {fprintf (stderr, "Parse_cmd () error.\n" ); exit (-1);} strcpy (Active_count, "0"),//strcpy (Active_count, "1"),/*printf ("active_count=%s\n", Active_count);p rintf ("High_ Count=%s\n ", High_count);p rintf (" total_count=%s\n ", Total_count), */if (!strcmp (Active_count," 0 ")) {if (hour>=0 && Hour<=6 | | hour==) {if (!strcmp ("auto_ssh_sbc_10_17.sh", Argv[1])) {ret=read_time_file (long_time,sbc_gg_long_time_file); if (ret!=0 {fprintf (stderr, "Read_time_file (sbc_gg_long_time_file) error.\n");}} else if (!strcmp ("auto_ssh_sbc_11_17.sh", Argv[1])) {ret=read_time_file (long_time,sbc_yz_long_time_file); if (ret!=0 {fprintf (stderr, "Read_time_file (sbc_yz_long_time_file) error.\n");}}} else if (hour>6 && hour<=22) {if (!strcmp ("auto_ssh_sbc_10_17.sh", Argv[1]) {Ret=read_time_file (Short_ Time,sbc_gg_short_time_file), if (ret!=0) {fprintf (stderr, "Read_time_file (sbc_gg_short_time_file) error.\n");}} else if (!strcmp ("auto_ssh_sbc_11_17.sh", Argv[1])) {ret=read_time_file (short_time,sbc_yz_short_time_file); if (ret! =0) {fprintf (stderr, "Read_time_file (sbc_yz_short_time_file) error.\n");}}} else {Exitstatus=unknown;}} else {if (!strcmp ("auto_ssh_sbc_10_17.sh", Argv[1])) {Fp=fopen (Sbc_gg_short_time_file, "w+"); fprintf (FP, "%d", 0); fp= fopen (Sbc_gg_long_time_file, "w+"); fprintf (FP, "%d", 0);} else if (!strcmp ("auto_ssh_sbc_11_17.sh", argv[1]) {Fp=fopen (Sbc_yz_short_time_file, "w+"); fprintf (FP, "%d", 0); Fp=fopen (Sbc_yz_long_time_file, "w+"); fprintf (FP, "%d", 0);} Ret=fclose (FP);} exitstatus=ok;sprintf (Status_information, "active_count=%s, high_count=%s, total_count=%s", Active_count,high_ Count,total_count); sprintf (Performance_data, "active_count=%s;;;; high_count=%s;;;; total_count=%s;;;;", Active_ Count,high_count,total_count); /*if (Strstr (argv[1], "148")) {if (!strcmp (active_ip_addr, "114.66.80.148") &&!strcmp (active_status, "active" ) {exitstatus=ok;sprintf (status_information, "F5 active=%s, standby=%s", "114.66.80.148", "114.66.80.149"); sprintf ( Performance_data, "master=%d;;;; slave=%d;;;; ", 1,0); }//else if (!strcmp (active_ip_addr, "114.66.80.149") &&!strcmp (active_status, "active")) {else if (!strcmp ( ACTIVE_IP_ADDR, "114.66.80.148") &&!strcmp (active_status, "standby")) {exitstatus=warning;sprintf (status_ Information, "F5 active=%s, standby=%s", "114.66.80.149", "114.66.80.148"); sprintf (Performance_data, "master=%D;;;; slave=%d;;;; ", 0, 1); }}else if (Strstr (argv[1], "149")) {if (!strcmp (active_ip_addr, "114.66.80.149") &&!strcmp (Active_status, " Standby ")) {exitstatus=ok;sprintf (status_information," F5 active=%s, standby=%s "," 114.66.80.148 "," 114.66.80.149 "); sprintf (Performance_data, "master=%d;;;; slave=%d;;;; ", 1,0); }//else if (!strcmp (active_ip_addr, "114.66.80.148") &&!strcmp (active_status, "active")) {else if (!strcmp ( ACTIVE_IP_ADDR, "114.66.80.149") &&!strcmp (active_status, "active")) {exitstatus=warning;sprintf (status_ Information, "F5 active=%s, standby=%s", "114.66.80.149", "114.66.80.148"), sprintf (Performance_data, "master=%d;;;; slave=%d;;;; ", 0, 1); }}*/printf ("%s:%s | %s\n ", exit_status[exitstatus],status_information,performance_data); return exitstatus;}
VI auto_ssh_sbc_10_17.sh
#!/usr/bin/expect-f#set Port 22set User Userset host 10.127.10.17#set host 114.66.80.149set password Password#set timeout -1set timeout 10#spawn ssh-d $port [email protected] $host #spawn ssh [email protected] $host date#spawn ssh [email protect ED] $host b failover show \; IP AD | grep ' inet 114.66.80.14 ' # #spawn SSH [email protected] $host show sessions#spawn ssh [email protected] $hostspawn Telnet $hos Texpect "*assword:*" send "$password \ r" Expect ' *>* ' send "show sessions\r" expect EOF
VI auto_ssh_sbc_11_17.sh
#!/usr/bin/expect-f#set Port 22set User Userset host 10.127.11.17#set host 114.66.80.149set password Password#set timeout -1set timeout 10#spawn ssh-d $port [email protected] $host #spawn ssh [email protected] $host date#spawn ssh [email protect ED] $host b failover show \; IP AD | grep ' inet 114.66.80.14 ' # #spawn SSH [email protected] $host show sessions# #spawn ssh [email protected] $hostspawn Telnet $ho Stexpect "*assword:*" send "$password \ r" Expect ' *>* ' send "show sessions\r" expect EOF
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Nagios Plugin Login SBC Monitor Phone number