顯示具有 cacti 標籤的文章。 顯示所有文章
顯示具有 cacti 標籤的文章。 顯示所有文章

2020年9月22日

cacti 使用非標準 mysql port

cacti 設定檔 include/{config.php,global.php}
預設為
$database_type = 'mysql';
$database_default = 'cacti';
$database_hostname = 'localhost';
$database_username = 'cactiuser';
$database_password = 'cactiuser';
$database_port = '3306';
$database_retries = 5;
$database_ssl = false;
$database_ssl_key = '';
$database_ssl_cert = '';
$database_ssl_ca = '';

若要使用非標準port、則要改成
$database_type = 'mysqli';
$database_default = 'cacti';
$database_hostname = '127.0.0.1';
$database_username = 'cactiuser';
$database_password = 'cactiuser';
$database_port = '3307';
$database_retries = 5;
$database_ssl = false;
$database_ssl_key = '';
$database_ssl_cert = '';
$database_ssl_ca = '';

Reference:https://forums.cacti.net/viewtopic.php?f=2&t=49756

2020年9月18日

line notify for cacti 1.x 20200921更新版

1. vim thold_functions.php 找到「function thold_mail」這個 Function,在最後的「return '';」上方加入以下程式碼:
2.把 your_line_token 改成自己使用的 token
/* LINE訊息告警 */
thold_debug("LINE alert-----------------");
$ttime=date("Y/m/d h:i:sa");
$content = trim("$subject")."\n"."\n".$ttime;
if ($data != '') {
    foreach ($data as $val) {
        $ffile = fopen("/tmp/qq.png","w+");
        fwrite($ffile,$val);
        fclose($ffile);
        $linefields = array('message' => $content,
                            'imageFile' => curl_file_create('/tmp/qq.png'));
        line_notify($linefields);
        unlink('/tmp/qq.png');
    }
}else{
    $linefields = array('message' => $content);
    line_notify($linefields);
}
thold_debug("LINE alert-----------------");
/* LINE訊息告警 */


3.一樣在「function thold_mail」這個 Function裡面找到
$attachments[] = array(
    'attachment' => rrdtool_function_graph($val['local_graph_id'], '', $graph_data_array, ''),
    'filename' => 'graph_' . $val['local_graph_id'] . '.png',
    'mime_type' => 'image/png',
    'local_graph_id' => $val['local_graph_id'],
    'local_data_id' => $val['local_data_id'],
    'inline' => 'inline'
);

下面一行加上
/* LINE訊息告警 */
$data1 = @rrdtool_function_graph($val['local_graph_id'], '', $graph_data_array);
array_push($data, $data1);
/* LINE訊息告警 */


4.在function thold_mail」這個 Function,在最後的「return '';」下方加入以下程式碼
/* LINE訊息告警 */
function line_notify($linefields){
    $ch = curl_init();
    $lineurl="https://notify-api.line.me/api/notify" ;
    $linehead=array("Content-Type: multipart/form-data",
                        "Authorization: Bearer your_line_token");
    curl_setopt($ch, CURLOPT_URL, $lineurl);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $linehead);
    curl_setopt($ch, CURLOPT_NOBODY, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $linefields);
    curl_exec($ch);
    curl_close($ch);
}
/* LINE訊息告警 */


cacti 1.x 簡單筆記

wget https://www.cacti.net/downloads/cacti-latest.tar.gz
wget https://www.cacti.net/downloads/spine/cacti-spine-latest.tar.gz

yum install net-snmp-devel mysql-devel openssl-devel gcc autoconf automake libtool dos2unix help2man

tar zxvf cacti-latest.tar.gz
mv cacti-1.2.14 cacti
cd cacti
mkdir -p rra log
chmod 2664 rra log
cd include
vim config.php
vim globe.php
mysql -p -e "create database cacti;grant all on cacti.* to 'cacti'@'localhost' identified by 'password';"
mysql -p cacti < cacti.sql


tar zxvf cacti-spine-latest.tar.gz
cd cacti-spine.1.2.14
./bootstrap
./configure
make && make install
chown root:root /usr/local/spine/bin/spine
chmod +s /usr/local/spine/bin/spine
cd /usr/local/spine/etc
cp spine.conf.dist spine.conf
vim spine.conf


check cacti setting
path, poller

2020年9月16日

cacti 使用 cli 新增 host 和 graph

新增 host 先編輯 host 資料 name ip snmp-port srv111 192.168.1.111 11161
srv112 192.168.1.112 11161
srv113 192.168.1.113 11161
srv114 192.168.1.114 11161
srv115 192.168.1.115 11161
使用下面指令查一下要使用的 templates # php add_device.php --list-host-templates
Valid Device Templates: (id, name)
0 None
1 Cisco Router
2 Generic SNMP Device
3 Net-SNMP Device
4 Windows Device
編輯 shell script 檔 #!/bin/bash

while read HOST IP PORT
do
    php add_device.php --description=${HOST} --ip=${IP} --port=${PORT} --community=public --template=3;
done < ./srv-host


查詢 id
php add_graphs.php --list-hosts
新增 graphs #!/bin/bash
#硬碟容量
for id in {1..5}
do
    hostname=`php add_graphs.php --list-hosts |grep "^${id}"|awk '{print $4}'`
    disks=`php add_graphs.php --list-snmp-values --host-id=${id} --snmp-query-id=2 --snmp-field=dskDevice | grep -Ev "${id}|usb"`
    for disk in ${disks}
    do
         echo "${id} ${hostname} ${disk}"
         php add_graphs.php --host-id=${id} --graph-type=ds --graph-template-id=25 --snmp-query-id=2 --snmp-query-type-id=16 --snmp-field=dskDevice --snmp-value=${disk}
    done

#網卡容量
    names=`php add_graphs.php --list-snmp-values --host-id=${id} --snmp-field=ifName | grep -Ev "${id}|usb"`
    for name in ${names}
    do
         echo "${id} ${hostname} ${name}"
         php add_graphs.php --host-id=${id} --graph-type=ds --graph-template-id=4 --snmp-query-id=1 --snmp-query-type-id=5 --snmp-field=ifName --snmp-value=${name}
    done
done
參數取得 --graph-template-id=    --host-id=[ID] --list-graph-templates
--snmp-query-id=    --host-id=[ID] --list-snmp-queries
--snmp-query-type-id=    --host-id=[ID] --list-query-types --snmp-query-id=[ID]
--snmp-field=    --list-snmp-fields --host-id=[ID]
--snmp-value=    --list-snmp-values --host-id=[ID] --snmp-field=[Filed]

reference:
https://blog.xuite.net/misgarlic/weblogic/47243432
https://www.itread01.com/content/1549017217.html
https://developer.aliyun.com/article/429541
http://napmas.blogspot.com/2011/09/cacti-command-line-interface.html

2020年9月14日

cacti 2020/9/13 後故障微修正

github 上 issues Unix timestamps after Sep 13 2020 are rejected as graph start/end arguments #3245 https://github.com/Cacti/cacti/issues/3245 如果使用的是 cacti 1.x 版本的話,已經在 1.2.10 修正了
但是自己目前使用的0.8.8h就只能自己來了 1.修改 graph_image.php if (!empty($_GET["graph_start"]) && $_GET["graph_start"] < 1600000000) { 改成 if (!empty($_GET["graph_start"]) && $_GET["graph_start"] < FILTER_VALIDATE_MAX_DATE_AS_INT) {
if (!empty($_GET["graph_end"]) && $_GET["graph_end"] < 1600000000) { 改成 if (!empty($_GET["graph_end"]) && $_GET["graph_end"] < FILTER_VALIDATE_MAX_DATE_AS_INT) {
2.在 include/global_constants.php 最後面加上 define('FILTER_VALIDATE_MAX_DATE_AS_INT', 2088385563);
3.修改 graph_xport.php if (!empty($_GET["graph_start"]) && is_numeric($_GET["graph_start"]) && $_GET["graph_start"] < 1600000000) { 改成 if (!empty($_GET["graph_start"]) && is_numeric($_GET["graph_start"]) && $_GET["graph_start"] < FILTER_VALIDATE_MAX_DATE_AS_INT
if (!empty($_GET["graph_end"]) && is_numeric($_GET["graph_end"]) && $_GET["graph_end"] < 1600000000) { 改成 if (!empty($_GET["graph_end"]) && is_numeric($_GET["graph_end"]) && $_GET["graph_end"] < FILTER_VALIDATE_MAX_DATE_AS_INT
這邊只有修正時間區塊被鎖死在1天以上的問題、但是至少不會被鎖死只能看一天以上的時間區間了

2020年8月6日

cacti 0.88b 無法開啟 "Graph Management"

log 出現 [error] "PHP message: PHP Fatal error: Cannot redeclare graph() in /home/cacti/graphs.php on line 1355" while reading response header from upstream
google Cannot redeclare graph() in /home/cacti/graphs.php on line 1355" while reading response header from upstream
參考這篇文章 https://forums.cacti.net/viewtopic.php?t=46455 # yum remove graphviz graphviz-php
# service php-fpm restart

2020年3月5日

cacti 使用 line notify 告警(含圖片輸出)

原本照 新添LINE訊息告警 Cacti網管更即時 文章、透過 IFTTT 告警。但是發現某些時候都會 delay 很久,所以另外找方法改成使用 curl 方式直接接 line api。
已測試版本:0.88b

1.一樣編緝thold_functions.php,找到「function thold_mail」這個 Function,在最後的「return '';」上方加入以下程式碼:
2.把 your_line_token 改成自己使用的 token
/* LINE訊息告警 */
list($a,$b) = explode("Message:",$text['text']);
$ttime=date("Y/m/d h:i:sa");
if ($b != '') {
$content=trim("$b")."\n"."\n".$ttime;
}else{
$content=$subject;
}

if ($data != '') {
$ffile = fopen("/tmp/qq.jpg","w+");
fwrite($ffile,$data);
fclose($ffile);
$linefields = array('message' => $content,
'imageFile' => curl_file_create('/tmp/qq.jpg'));
}else{
$linefields = array('message' => $content);
}

$ch = curl_init();
$lineurl="https://notify-api.line.me/api/notify" ;
$linehead=array("Content-Type: multipart/form-data",
"Authorization: Bearer your_line_token");
curl_setopt($ch, CURLOPT_URL, $lineurl);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $linehead);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $linefields);
curl_exec($ch);
curl_close($ch);
if(file_exists('/tmp/qq.jpg')){
unlink('/tmp/qq.jpg');
}



上面程式放到 github 上,方便複製
https://github.com/zhuccc/cacti_thold_line

Ref:
新添LINE訊息告警 Cacti網管更即時
CACTI Alert 增加 LineNotify