cacti分組發飛信模塊開發
功能:
1、在閾值配置頁面添加手機號碼輸入框
2、實現不同閾值發送不同的手機號碼
實現過程:
1、修改數據庫:修改thold_data,和thold_template表分別添加字段“mobile”,varchar類型,長度15
2、修改thold.php
1)在$form_array = array()的最後添加代碼:
'mobile' => array(
'friendly_name' => '報警短信手機號碼',
'method' => 'textarea',
'textarea_rows' => 3,
'textarea_cols' => 50,
'description' => '您可以在這裏指定接收報警短信的手機號碼(多個手機號碼用英文逗號分隔)',
'value' => isset($thold_item_data['mobile']) ? $thold_item_data['mobile'] : ''
),
2)在_f.notify_extra.disabled = status;的下面添加代碼:
_f.mobile.disabled = status;
3、用php封裝飛信發送接口得到PHPFetion.php,放到plugins/thold/下
4、修改thold_functions.php
1)在開頭添加代碼
require 'PHPFetion.php';
function sendsms($mobile,$sms){
$fetion = new PHPFetion('手機號碼', '飛信密碼'); // 手機號、飛信密碼
$fetion->send($mobile, $sms); // 接收人手機號、飛信內容
}
2)在thold_check_threshold函數中添加代碼:$mobile = $item['mobile'];
3)在所有下面代碼的後面
if (trim($alert_emails) != '')
thold_mail($alert_emails, '', $subject, $msg, $file_array);
添加發送飛信代碼
if (trim($mobile) != '')
sendsms($mobile,$subject);
4)在
$save['notify_extra'] = (trim($_POST['notify_extra'])) == '' ? '' : $_POST['notify_extra'];
的下面添加代碼:
$save['mobile'] = (trim($_POST['mobile'])) == '' ? '' : $_POST['mobile'];
5)在
$insert['notify_extra'] = $template[$y]['notify_extra'];
的下面添加代碼:
$insert['mobile'] = $template[$y]['mobile'];
6)在
thold_data.notify_extra = thold_template.notify_extra,
的下面添加代碼:
thold_data.mobile = thold_template.mobile,
7)在
thold_data.notify_extra = thold_template.notify_extra,
的下面添加代碼:
thold_data.mobile = thold_template.mobile,
8)在
if (trim($alert_emails) != '' && $item['restored_alert'] != 'on')
thold_mail($alert_emails, '', $subject, $msg, $file_array);
的下面添加代碼:
if (trim($mobile) != '' && $item['restored_alert'] != 'on')
sendsms($mobile,$subject);
5、修改thold_templates.php
1)在$form_array = array()的最後添加代碼:
'mobile' => array(
'friendly_name' => '報警短信手機號碼',
'method' => 'textarea',
'textarea_rows' => 3,
'textarea_cols' => 50,
'description' => '您可以在這裏指定接收報警短信的手機號碼(多個手機號碼用英文逗號分隔)',
'value' => isset($thold_item_data['mobile']) ? $thold_item_data['mobile'] : ''
),
2)在$save['notify_extra'] = $_POST['notify_extra'];的下面添加代碼:
$save['mobile'] = $_POST['mobile'];
6、修改thold.sql
1)在notify_extra varchar(255) NOT NULL default '',的下面添加代碼:
mobile varchar(15) NOT NULL default '',
2)在`notify_extra` varchar(255) default NULL,的下面添加代碼:
`mobile` varchar(15) default NULL,
7、修改thold_add.php
在$insert['notify_extra'] = $template['notify_extra'];的下面添加代碼:
$insert['mobile'] = $template['mobile'];