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

本文介绍了一个用于监控Asterisk电话系统的C语言脚本。该脚本通过调用Asterisk的命令行接口获取当前活动呼叫的数量,并将状态信息及性能数据输出为标准的监控格式。此工具适用于系统管理员进行远程监控和故障排查。

AI 驱动代码审查实战

Claude code-review 插件深度解析,把 AI 智能审查接进 CI/CD 流水线

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

AI 驱动代码审查实战

Claude code-review 插件深度解析,把 AI 智能审查接进 CI/CD 流水线

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值