Cacti集成

本文介绍如何对Cacti监控源进行集成对接。

简介

Cacti是一套基于PHP、MySQL、SNMPRRDTool开发的网络流量监测图形分析工具,运维事件中心支持简单、快速的集成Cacti,实现报警和事件的统一管理;查看以下集成步骤完成告警记录集成。

如何集成Cacti监控?

步骤1:找到Cacti监控源

登录运维事件中心在左侧导航栏选择集成中心 > 集成配置,菜单找到Cacti监控源,进入Cacti的新增集成页面查看集成步骤完成集成接入。

步骤2:增加报警媒介

前提说明:已经安装并配置thold插件,已配置邮件告警。

  1. 修改 {cacti_home}/plugins/thold/thold_functions.phpthold_mail函数中加入调用aliyunalert_for_cacti($message,$subject):

    function thold_mail($to_email, $from_email, $subject, $message, $filename, $headers = array()) {
     thold_debug('Preparing to send email');
     $subject = trim($subject);
     $message = str_replace('<SUBJECT>', $subject, $message);
     aliyunalert_for_cacti($message,$subject);
     if ($from_email == '') {
      $from_email = read_config_option('thold_from_email');
      $from_name  = read_config_option('thold_from_name');
  2. 在 function thold_mail函数后添加aliyunalert_for_cacti函数并将$ch = curl_init("URL")中的ULR替换为以下URL地址:

    https://public-alert.aliyuncs.com/event/cacti/{集成密钥}
    说明

    以上URL中的集成密钥为cacti监控源的集成密钥。

    function aliyunalert_for_cacti($msg, $subject) {                    $fields = array(
                           "subject"  =>  $subject,
                           "msg"  =>   $msg
                        );
                        $fieldsdate = json_encode($fields);
                        $ch = curl_init("URL");
                        curl_setopt($ch, CURLOPT_HEADER, "Content-type: application/json");
                        curl_setopt($ch, CURLOPT_POST, 1);
                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                        curl_setopt($ch, CURLOPT_POSTFIELDS, $fieldsdate);
                        $output = curl_exec($ch);
                        if(curl_errno($ch)){
                           print curl_error($ch);
                        }
                        curl_close($ch);
                        echo $output;
                      }

步骤3:确认集成

完成以上配置后点击集成密钥下的确认集成按钮完成cacti的集成配置。

步骤4:确认发送成功

查看Cacti日志,出现邮件发送成功即为发送成功。

Cacti发送成功标记

步骤5:验证集成是否成功

Cacti侧报警记录发送成功后,若在集成配置页面查看到Cacti监控源状态为“已接收”报警则说明已集成成功。