zpjx 发表于 2015-11-22 17:02:10

nagios插件之计算asterisk当前通话量

  vi check_call.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define OK       0
#define WARNING1
#define CRITICAL 2
#define UNKNOWN3
#define LEN 1023
int main() {
int ret;
FILE *fp;
char readbuf;
int exitstatus=OK;
char *exit_status={&quot;OK&quot;,&quot;WARNING&quot;,&quot;CRITICAL&quot;,&quot;UNKNOWN&quot;};
int i;
char *p,*str;
char status_information;
char performance_data;
fp=popen(&quot;/usr/sbin/asterisk -r -x 'core show calls'&quot;,&quot;r&quot;);
if(fp==NULL) {
fprintf(stderr,&quot;popen() error. &quot;);
exitstatus=CRITICAL;
printf(&quot;%s: - %s | %s\n&quot;,exit_status,status_information,performance_data);
return exitstatus;
}
while(fgets(readbuf,1024,fp)!=NULL) {
for(p=strtok(readbuf,&quot; &quot;);p;p=strtok(NULL,&quot; &quot;)) {
//      str=p;
sprintf(status_information,&quot;active calls=%s&quot;,p);
sprintf(performance_data,&quot;calls=%s;;;;&quot;,p);
break;
}
break;
}
ret=fclose(fp);
if(fp==NULL) {
fprintf(stderr,&quot;popen() error.\n&quot;);
return -1;
}
printf(&quot;%s: %s | %s\n&quot;,exit_status,status_information,performance_data);
return exitstatus;
}
页: [1]
查看完整版本: nagios插件之计算asterisk当前通话量