zabbix监控之奥科语音网关M10K电话并发数

本文介绍如何在Zabbix中添加自定义监控项,通过编写shell脚本和C语言程序,实现对特定设备的VoIP呼叫状态进行监控。详细步骤包括在zabbix_agent.conf中配置UserParameter,创建并调用外部脚本,以及解析设备返回的数据。

zabbix管理页面添加item项

voip_calls[auto_ssh_audiocode_102_49.sh]

vi /etc/zabbix/zabbix_agent.conf 添加自定义脚本

UserParameter=voip_calls[*],/usr/lib/zabbix/externalscripts/audiocode_calls_status $1

vi  auto_ssh_audiocode_102_49.sh

#!/usr/bin/expect -f

set port 22
set user xxxxx
set password xxxxx
set host 172.24.102.49
set timeout 30

#spawn ssh -D $port $user@$host
#spawn ssh $user@$host date
#spawn ssh $user@$host b failover show \; ip ad | grep 'inet 114.66.80.14'
##spawn ssh $user@$host show sessions
#spawn ssh $user@$host
spawn ssh -p $port $user@$host

expect "Admin@172.23.102.49's password:"
send "$password\r"

#expect "*assword:*" { send "$password\r" }
#expect "*assword:*"
#send "$password\r"

#expect '*>*' { send "show sessions\r" }
##expect '*Mediant*>'

#send "\r"
#expect '*1000>'
#send "show voip calls list\r"
#send "show voip calls active\r"

expect "Mediant 1000>"
send "show voip calls statistics gw\r"

expect "Mediant 1000>"
send "quit\r"

expect eof

vi audiocode_calls_status.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define OK       0
#define WARNING  1
#define CRITICAL 2
#define UNKNOWN  3

#define LEN 100

//#define TCL_CMD "/home/weihu/tcl/"
//#define TCL_CMD "/usr/local/nagios/libexec/"
#define TCL_CMD "/usr/lib/zabbix/externalscripts/"

int exitstatus=OK;
char *exit_status[4]={"OK","WARNING","CRITICAL","UNKNOWN"};

char status_information[LEN];
char performance_data[LEN];

//int parse_status(char *sh_cmd,char *active_count,char *high_count,char *total_count) {
int parse_status(char *sh_cmd,char *active_count) {
        int ret;
        FILE *fp;

        char readbuf[LEN];

        char *p,*str;

        int i=0;
        int line=0;
        int mark=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) {
        //      printf("%s",readbuf);
        //      line++;
        ////    if(strstr(readbuf,"No Active") || strstr(readbuf,"show voip calls")) {
                if(strstr(readbuf,"No Active")) {
                //      printf("111111111111111111\n");
                        strcpy(active_count,"0");
                        mark=1;
                }
        ////    else if(strstr(readbuf,"Total Active Calls")) {
                else if(strstr(readbuf,"Active TDM channels")) {
                //      printf("22222222222222222\n");
                ////    sscanf(readbuf,"Total Active Calls: %s",active_count);
                        sscanf(readbuf,"Active TDM channels: %s",active_count);
                        mark=1;
                }

                if(mark==1) {
                        break;
                }
        }
//      printf("active_count=%s\n",active_count);

        ret=fclose(fp);
        if(fp==NULL) {
                fprintf(stderr,"popen() error.\n");
                return -1;
        }

        return 0;
}

int main(int argc, char *argv[]) {
        int ret;
        char sh_cmd[LEN];

        char active_count[LEN];
        char high_count[LEN];
        char total_count[LEN];

        char active_ip_addr[LEN];

        if(argc<=1) {
        //      printf("%s %s\n",argv[0],"auto_ssh_audiocode_212_32.sh | auto_ssh_audiocode_212_32.sh");
                printf("example: %s %s\n",argv[0],"auto_ssh_audiocode_212_32.sh");
                exit(-1);
        }

        sprintf(sh_cmd,"%s%s",TCL_CMD,argv[1]);
//      printf("sh_cmd=%s\n",sh_cmd);

        memset(active_count,0,LEN);
        strcpy(active_count,"0");

//      ret=parse_status(sh_cmd,active_count,high_count,total_count);
        ret=parse_status(sh_cmd,active_count);
        if(ret!=0) {
                fprintf(stderr,"parse_status() error.\n");
                exit(-1);
        }

/*
        printf("active_count=%s\n",active_count);
        printf("high_count=%s\n",high_count);
        printf("total_count=%s\n",total_count);
*/


        exitstatus=OK;
//      sprintf(status_information,"active_count=%s, high_count=%s, total_count=%s",active_count,high_count,total_count);
        sprintf(status_information,"active_count=%s",active_count);
//      sprintf(performance_data,"active_count=%s;;;; high_count=%s;;;; total_count=%s;;;;",active_count,high_count,total_count); 
        sprintf(performance_data,"active_count=%s;;;;",active_count); 

//      printf("%s: %s | %s\n",exit_status[exitstatus],status_information,performance_data);
        printf("%s\n",active_count);

        return exitstatus;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值