vi check_call.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define OK 0
#define WARNING 1
#define CRITICAL 2
#define UNKNOWN 3
#define LEN 1023
int main() {
int ret;
FILE *fp;
char readbuf[1024];
int exitstatus=OK;
char *exit_status[4]={"OK","WARNING","CRITICAL","UNKNOWN"};
int i;
char *p,*str;
char status_information[LEN];
char performance_data[LEN];
fp=popen("/usr/sbin/asterisk -r -x 'core show calls'","r");
if(fp==NULL) {
fprintf(stderr,"popen() error. ");
exitstatus=CRITICAL;
printf("%s: - %s | %s\n",exit_status[exitstatus],status_information,performance_data);
return exitstatus;
}
while(fgets(readbuf,1024,fp)!=NULL) {
for(p=strtok(readbuf," ");p;p=strtok(NULL," ")) {
// str=p;
sprintf(status_information,"active calls=%s",p);
sprintf(performance_data,"calls=%s;;;;",p);
break;
}
break;
}
ret=fclose(fp);
if(fp==NULL) {
fprintf(stderr,"popen() error.\n");
return -1;
}
printf("%s: %s | %s\n",exit_status[exitstatus],status_information,performance_data);
return exitstatus;
}
本文介绍了一个用于监控Asterisk电话系统的C语言脚本。该脚本通过调用Asterisk的命令行接口获取当前活动呼叫的数量,并将状态信息及性能数据输出为标准的监控格式。此工具适用于系统管理员进行远程监控和故障排查。

2984

被折叠的 条评论
为什么被折叠?



