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