运行: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
#define 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);
printf("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");
printf("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(tmpbuf,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;

//Sun
mark1++;

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;
}
*/
}

nagios插件之登陆SBC监控电话数的更多相关文章

  1. nagios插件之登陆防火墙实现session监控

    ssh_firewall_session.sh -- 登陆防火墙并运行dis session statistics firewall_check_sessions.c -- 调用上面脚本.过滤出ses ...

  2. Nagios配置—添加linux主机监控

    nagios安装请参看:Nginx平台安装Nagios监控服务 下面是我添加linux监控机的过程,如有错误或者不当的地方请指出: 测试环境: 监控主机:nagios+nagios插件+nrpe+网站 ...

  3. 使用nagios插件 check_mysql_health 过程中遇到的error

    使用nagios插件 check_mysql_health 过程中遇到的error 1.如果在运行监控mysql插件的时候遇到了error安装以下依赖包就可以解决: yum install perl- ...

  4. Eclipse下使用GDT插件无法登陆GAE & GDT无法上传JAVA代码

    今天更新github主页的过程中,想使用GAE部署一个Java Web服务来更好的支持网站动态性(关键是利用了免费的GAE资源),结果遇到了2个大问题. 1.GDT插件无法登陆GAE账户 错误1:登陆 ...

  5. 开发人员福利!ChromeSnifferPlus 插件正式登陆 Chrome Web Store

    今天(2014-10-30)下午,ChromeSnifferPlus 插件正式登陆 Chrome Web Store. 在线安装地址: https://chrome.google.com/websto ...

  6. jmeter使用笔记——脚本录制,JMeter使用plugins插件进行服务器性能监控

    脚本录制: 1.badboy录制 2.代理服务器录制 ①工作台添加HTTP代理服务器 ②设置目标控制器,分组,排除模式,包含模式(使用正则表达式筛选) ③设置浏览器,手动设置代理服务器,localho ...

  7. nagios 插件ndoutils 安装配置

    nagios 插件ndoutils 安装配置 原文地址:http://www.cnblogs.com/caoguo/p/5022645.html # Nagios install ndoutils # ...

  8. nagios插件nagiosql安装配置

    nagios插件nagiosql安装配置 # Nagiosql install [root@Cagios ~]# yum install -y libssh2 libssh-devel [root@C ...

  9. JMeter使用plugins插件进行服务器性能监控

    JMeter使用plugins插件进行服务器性能监控 性能测试时,我们的关注点有两部分 1 服务本身:并发响应时间 QPS 2 服务器的资源使用情况:cpu memory I/O disk等 JMet ...

随机推荐

  1. pg 创建自增id

    CREATE SEQUENCE original_site_id_seq START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1; 先创 ...

  2. [转] Makefile 基础 (7) —— Makefile 中 make 的运行

    该篇文章为转载,是对原作者系列文章的总汇加上标注. 支持原创,请移步陈浩大神博客:(最原始版本) http://blog.csdn.net/haoel/article/details/2886 我转自 ...

  3. 关于oracle 11g导出的dmp文件无法导入10g的问题

    今天遇到一个问题,由于无法远程11g是数据库服务器,只能用exp命令导出了一张表的dmp文件:在本地导入时遇到如下错误: IMP-00010: 不是有效的导出文件, 头部验证失败IMP-00000: ...

  4. 在idea中部署远程Tomcat

    实现效果:在idea中点击run时,自动将代码编译并上传.部署到远程服务器中 和传统的在本地服务器相比较的优势:1.节省开发者开发机的资源,省去了本地服务器的CPU.内存的占用.2.如果开发的程序为A ...

  5. Pushlets的初始化陷阱

    Pushlets是在类名为Pushlet的servlet的init方法中进行初始化的.一般我们会在web.xml配置pushlet的时候,指定其servlet在Web应用启动时就进行初始化,即便这样, ...

  6. angular关于依赖注入

    <html> <head> <title>Angular JS Forms</title> </head> <body> < ...

  7. Linux Malloc分析-从用户空间到内核空间【转】

    转自:http://blog.csdn.net/ordeder/article/details/41654509 版权声明:本文为博主(http://blog.csdn.net/ordeder)原创文 ...

  8. C 语言 文件读写

    在ANSI C中,对文件的操作分为两种方式,即流式文件操作和I/O文件操作,下面就分别介绍之.一.流式文件操作 这种方式的文件操作有一个重要的结构FILE,FILE在stdio.h中定义如下:type ...

  9. 使用 IntelliJ IDEA 开发 Android 应用程序时配置 Allatori 进行代码混淆

    IntelliJ IDEA 提供了非常强大的 Android 开发支持,就连 Google 官方推荐的 Android Studio 其实也是 IntelliJ IDEA 的一个 Android 开发 ...

  10. HDU 5794 A Simple Chess(杨辉三角+容斥原理+Lucas定理)

    题目链接 A Simple Chess 打表发现这其实是一个杨辉三角…… 然后发现很多格子上方案数都是0 对于那写可能可以到达的点(先不考虑障碍点),我们先叫做有效的点 对于那些障碍,如果不在有效点上 ...