nagios插件之监控f5pool中cngw主机session数

使用方法:f5_session_cngw_prod -H host -o oid

vi f5_session_cngw_prod.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#define OK       0
#define WARNING  1
#define CRITICAL 2
#define UNKNOWN  3

#define LEN 1000
#define LEN_SHORT 512

int exitstatus=OK;
char *exit_status[4]={"OK","WARNING","CRITICAL","UNKNOWN"};

char *power_status[4]={"active","deactive","not_install","unsupport"};

char status_information[LEN];
char performance_data[LEN];

int sum_conn;
char sum_conn_all[LEN_SHORT];

char sum_conn_170_245[LEN_SHORT];
char sum_conn_171_245[LEN_SHORT];

void print_usage(char str[32]) {
        printf("Usage: %s [options]\n",str);
        printf("  e.g. %s -H 1.1.1.1 -o .1.3.6...\n",str);
        printf("Options:\n");
        printf("\t -H ip address\n");
        printf("\t -o snmp oid\n");
}  

/*
int check_argv() {
        while((ch=getopt(argc,argv,"H:o:"))!=-1) {
                switch(ch) {
                        case 'H':
                        //      printf("option H:%s\n",optarg);
                                break;
                        case 'o':
                        //      printf("option o:%s\n",optarg);
                                break;
                        default:
                        //      printf("other option :%c\n",ch);
                                break;
                        }
                }

        return -1;
}
*/

int parse_status(char *sh_cmd) {
        int ret;
        int line=0;
        FILE *fp;
        char readbuf[LEN_SHORT];

//      fp=popen("/usr/bin/snmpwalk -v2c  -c zb.186.nms 114.66.80.55 1.3.6.1.4.1.2011.2.23.1.9.1.2.1.2","r");
//      fp=popen(command,"r");
        fp=popen(sh_cmd,"r");
        if(fp==NULL) {
                fprintf(stderr,"fopen() error.\n");

                exitstatus=CRITICAL;
                return exitstatus;

/*
                sprintf(status_information,"active_status=%s",active_status);
                sprintf(performance_data,"active_status=%s;;;0;100","0");

                sprintf(status_information,"conn_170_245=%s conn_171_245=%s all_conn=%s",sum_conn_170_245,sum_conn_171_245,sum_conn_all);
                sprintf(performance_data,"conn_170_245=%s;;;0;100 conn_171_245=%s;;;0;100 all_conn=%s;;;0;100",sum_conn_170_245,sum_conn_171_245,sum_conn_all);

                printf("%s: %s | %s\n",exit_status[exitstatus],status_information,performance_data);

*/
        }

/*
        str=fgets(readbuf,LEN_SHORT,fp);
        if(str==NULL) {
                perror("fgets() error");
        }

        printf("readbuf=%s",readbuf);

        ret=sscanf(readbuf,"SNMPv2-SMI::enterprises.3375.2.1.1.1.1.19.0 = INTEGER: %s",active_status);
        if(ret<0) {
                fprintf(stderr,"sscanf() error.\n");

                exitstatus=UNKNOWN;

                sprintf(status_information,"active_status=%s",active_status);
                sprintf(performance_data,"active_status=%s;;;0;100","0");

                printf("%s: %s | %s\n",exit_status[exitstatus],status_information,performance_data);

                return exitstatus;
        }

//SNMPv2-SMI::enterprises.3375.2.1.1.1.1.19.0 = INTEGER:
*/

        while(fgets(readbuf,LEN_SHORT,fp)!=NULL) {
                line++;
        //      printf("line=%d,readbuf=%s",line,readbuf);

                if(line==1) {
                //      sscanf(readbuf,"SNMPv2-SMI::enterprises.3375.2.1.3.2.2.2.1.2.1 = INTEGER: %s",power1_value);
                //      sscanf("SNMPv2-SMI::enterprises.3375.2.2.5.4.3.1.9.7.77.81.65.95.73.78.84.1.4.103.4.170.245.8021 = Counter64: 23","%*[^=]%*[^:]: %s",str1);
                        sscanf(readbuf,"%*[^=]%*[^:]: %s",sum_conn_170_245);
                }
                else if (line==2) {
                //      sscanf(readbuf,"SNMPv2-SMI::enterprises.3375.2.1.3.2.2.2.1.2.2 = INTEGER: %s",power2_value);
                        sscanf(readbuf,"%*[^=]%*[^:]: %s",sum_conn_171_245);
                }

/*
                if(line==2) {
                        break;
                }
*/
        }

//      printf("line=%d\n",line);

        ret=pclose(fp);
        if(ret==-1) {
                perror("pclose");
        }

        return 0;
}

int main(int argc,char *argv[]) {
        int ret;

        int ch;
        int mark=0;

        char *str;

        char command[LEN];

        if(argc==1 || argc!=5) {
                printf("%s -H host -o oid\n",argv[0]);
                print_usage(argv[0]);
                return -1;
        } 

        while((ch=getopt(argc,argv,"H:o:"))!=-1) {
                switch(ch) {
                        case 'H':
                        //      printf("option H:%s\n",optarg);
                                break;
                        case 'o':
                        //      printf("option o:%s\n",optarg);
                                break;
                        default:
                        //      printf("other option :%c\n",ch);
                                mark=1;
                                break;
                }
        }

        if(mark==1) {
                return -1;
        }

//      sprintf(command,"/usr/bin/snmpwalk -v2c -c public %s %s | grep 245.6717",argv[2],argv[4]);
        sprintf(command,"/usr/bin/snmpwalk -v2c -c public %s %s | grep 50.52.53.6717",argv[2],argv[4]);
//      snmpwalk -v 2c -c zb.186.nms 114.66.80.53 1.3.6.1.4.1.3375.2.2.5.4.3.1.11 | grep "50.52.53.6717"

//      printf("command=%s\n",command);

        ret=parse_status(command);
        if(ret!=0) {
                fprintf(stderr,"parse_status() error.\n");
        }

        sum_conn=atoi(sum_conn_170_245)+atoi(sum_conn_171_245);
        sprintf(sum_conn_all,"%d",sum_conn);

/*
        printf("sum_conn_170_245=%s\n",sum_conn_170_245);
        printf("sum_conn_171_245=%s\n",sum_conn_171_245);

        printf("sum_conn_all=%s\n",sum_conn_all);
*/

        //status_information && performance_data
//      if(atoi(sum_conn_170_245)<=50 && atoi(sum_conn_171_245)<=50) {
                exitstatus=OK;

                sprintf(status_information,"conn_170_245=%s conn_171_245=%s all_conn=%s",sum_conn_170_245,sum_conn_171_245,sum_conn_all);
                sprintf(performance_data,"conn_170_245=%s;;;0; conn_171_245=%s;;;0; all_conn=%s;;;0;",sum_conn_170_245,sum_conn_171_245,sum_conn_all);
//      }
/*
        else if(atoi(sum_conn_170_245)>50 && atoi(sum_conn_170_245)<100 || atoi(sum_conn_171_245)>50 && atoi(sum_conn_171_245)<100) {
                exitstatus=WARNING;

                sprintf(status_information,"conn_170_245=%s conn_171_245=%s all_conn=%s",sum_conn_170_245,sum_conn_171_245,sum_conn_all);
                sprintf(performance_data,"conn_170_245=%s;;;0;100 conn_171_245=%s;;;0;100 all_conn=%s;;;0;100",sum_conn_170_245,sum_conn_171_245,sum_conn_all);
        }
        else if(atoi(sum_conn_170_245)>100 || atoi(sum_conn_171_245)>100) {
                exitstatus=CRITICAL;

                sprintf(status_information,"conn_170_245=%s conn_171_245=%s all_conn=%s",sum_conn_170_245,sum_conn_171_245,sum_conn_all);
                sprintf(performance_data,"conn_170_245=%s;;;0;100 conn_171_245=%s;;;0;100 all_conn=%s;;;0;100",sum_conn_170_245,sum_conn_171_245,sum_conn_all);

        }
*/

        printf("%s: %s | %s\n",exit_status[exitstatus],status_information,performance_data);

        return exitstatus;
}
时间: 2024-10-11 05:08:59

nagios插件之监控f5pool中cngw主机session数的相关文章

nagios通过check_traffic监控Linux,windows主机网卡流量

一,被监控端-Linux 1.安装snmp yum install net-snmp* 2.配置snmp [[email protected] ~]#grep -v "^#" /etc/snmp/snmpd.conf |grep -v "^$" com2sec notConfigUser  default       public com2sec notConfigUser  192.168.80.132       public group   notConfig

nagios插件之监控if8接口日志(新接口)

vi check_if8_log.c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <errno.h> #define OK 0 #define WARNING 1 #define CRITICAL 2 #define UNKNOWN 3 #define LEN 400000 int exitstatus=OK; char

nagios插件之监控if8接口日志

vi check_if8_log.c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <errno.h> #define OK 0 #define WARNING 1 #define CRITICAL 2 #define UNKNOWN 3 #define LEN 400000 int exitstatus=OK; char

nagios插件之监控多个tomcat线程数

vi check_tomcat_threads.c #include <stdio.h> #include <stdlib.h> #include <string.h> #define OK 0 #define WARNING 1 #define CRITICAL 2 #define UNKNOWN 3 #define LEN 1000 #define MIN_LEN 100 #define CMD1 "ps -efL | grep apache-tomcat

Nagios利用NSClient++监控Windows主机(4)

在Nagios的libexec下有check_nt这个插件,它就是用来检查windows机器的服务的.其功能类似于check_nrpe.不过还需要搭配另外一个软件NSClient++,它则类似于NRPE.我们需要下载NSClient合适的版本,然后安装在被监控的windows主机上. Overview of NRPE NSClient++的原理如下图: 可以看到NSClient与nrpe最大的区别就是: NRPE: 被监控机上安装有nrpe,并且还有插件,最终的监控是由这些插件来进行的.当监控主

Nagios利用NRPE监控Linux主机(3)

一.利用NRPE监控远程Linux的"本地信息" 上面已经对远程Linux 主机是否存活做了监控,而判断远程机器是否存活,我们可以使用ping 工具对其监测.还有一些远程主机服务,例如ftp.ssh.http,都是对外开放的服务,即使不用Nagios,我们也可以试的出来,随便找一台机器看能不能访问这些服务就行了.但是对于像磁盘容量,cpu负载这样的"本地信息",Nagios只能监测自己所在的主机,而对其他的机器则显得有点无能为力.毕竟没得到被控主机的适当权限是不可能

nagios利用NSCient监控远程window主机

摘要:1.NSCient原理2.NSClient++与NRPE NSClient++区别3.Nagios对window主机的监控 1 简介 Nagios对Windows主机的监控主要有三种方法 第一种是NSclient++ 第二种是NRPE 第三种是SNMP(不是很常用). 1.1 NSClient的工作原理 NSClient++是用来监控Windows主机时安装在Windows主机上的组件.被监控机上安装NSClient,,当监控主机将监控请求发给NSClient后,NSClient直接完成监

Nagios利用NSClient++监控Windows主机

一.简介 1.获取更多的NSClient原理,请参考NSClient++官方站点 NSClient++官网:http://www.nsclient.org/ 2.NSClient++与NRPE NSClient++的工作原理 NRPE的工作原理 Nagios对Windows主机的监控主要有三种方法 第一种是NSclient++ 第二种是NRPE 第三种是SNMP(不是很常用) NSclient++与nrpe最大的区别就是: 1.被监控机上安装有nrpe,并且还有插件,最终的监控是由这些插件来进行

Nagios利用NRPE监控Linux主机

一.简介 1.NRPE介绍 NRPE是Nagios的一个功能扩展,它可在远程Linux/Unix主机上执行插件程序.通过在远程服务器上安装NRPE插件及Nagios插件程序来向Nagios监控平台提供该服务器的本地情况,如CPU负载,内存使用,磁盘使用等.这里将Nagios监控端称为Nagios服务器端,而将远程被监控的主机称为Nagios客户端. Nagios监控远程主机的方法有多种,其方式包括SNMP,NRPE,SSH,NCSA等.这里介绍其通过NRPE监控远程Linux主机的方式. NRP