| 
 短信网关和zabbix对接后可以实现系统告警用短信或邮件推送到维护者,做到早预警早处理。 1、添加zabbix[1]短信数据源默认用户名密码和其他一样 即都为1 ID设置为8888  
 
修改邮件账户配置(不能连外网的不需要修改了) select t.*,t.rowid from  smc_cfg_sys t;  
2、在zabbix服务器上执行命令,增加客户端远程执行脚本的权限 sed -i '/# EnableRemoteCommands=0/a\EnableRemoteCommands=1'/usr/local/zabbix/etc/zabbix_agentd.conf 重启生效: service  zabbix_agentd  restart 3、配置zabbix用户、示警媒介、以及相关权限 配置zabbix要通知的用户,媒介类型选择SMS,此处没有特别重要的意义此处电话只为后续再数据库查询脚本做条件使用,可以不是联通号码,当然最好就是你的接受短消息号码  
 
可以随意新添加个用户比如“yhj”,群组就用administrators群组,  
 
  
 此处填写联通的手机号码,最好是接收短信的手机号
 
 许可权限把所有的机器都选上   
 添加动作: 
 在组态---动作--- 动作这里:默认 也可以改成我这样的 
 名称:send smc 默认接收人:服务器:{HOSTNAME1}发生: {TRIGGER.NAME}故障 默认信息: 告警主机:{HOSTNAME1}  
告警时间:{EVENT.DATE} {EVENT.TIME}  
告警信息: {TRIGGER.NAME}  
告警项目:{TRIGGER.KEY1}  
问题详情:{ITEM.NAME}:{ITEM.VALUE}  
当前状态:{TRIGGER.STATUS}:{ITEM.VALUE1} 条件这里: 可以自己定义把不需要短信警报的排除在外比如我上边就对主机群组路由器交换机进行了排除,示警度为咨询类(对集团上报文件做了监控,只是个通知)的也排除了。 操作: 1、添加入上图的配置 操作类型 送出消息,用户选择刚刚创建的”yhj”,送到”SMS”  
2、添加入上图的配置 操作类型 “远程命令”,类型为“自定义脚本”命令为 短信通知的为“curl 133.96.92.130/sendsms.php” 邮件通知的为:“curl 133.96.92.130/sendmail.php” 短信:  
邮件: 3、在/usr/local/nginx/html/目录下新建相关的sendsms.php [root@HEBGAT05 ~]# vi  /usr/local/nginx/html/sendsms.php 复制下边的文件内容进行修改 [root@HEBGAT05 ~]# cat/usr/local/nginx/html/sendsms.php <?php $host = '10.4.64.106'; $database = 'zabbix'; $username = 'root'; $password = 'Wyzx@415'; $connection = mysql_connect($host, $username,$password);//连接到数据库 mysql_query("set names 'utf8'");//编码转化 if (!$connection) {  die("could not connect to the database.\n" . mysql_error());//诊断连接错误 } $selectedDb = mysql_select_db($database);//选择数据库 if (!$selectedDb) {  die("could not to the database\n" . mysql_error()); } $query = "select subject  from alerts   where sendto='13073100823'   orderby eventid desc  LIMIT 1";//构建查询语句  
$result = mysql_query($query);//执行查询 if (!$result) {  die("could not to the database\n" . mysql_error()); } while ($row = mysql_fetch_row($result)) {   //取出结果并显示   $subject =$row[0];   echo"\n"; } mysql_close($connection); include('nusoap.php');  
  $client =new nusoap_client('h :8081/services/SmcService?wsdl','wsdl');   $err =$client->getError();   if ($err) {       echo'<h2>Constructor error</h2><pre>' . $err . '</pre>';   } $client ->soap_defencoding =  'utf-8' ; $client ->decode_utf8 = false; $client ->xml_encoding =  'utf-8' ; $param = array('username' => '1', 'password'=> 'c4ca4238a0b923820dcc509a6f75849b', 'type' => '2', 'src_id' =>'8888', 'level' => '1', 'to_users' =>'<PHONE>13073100823</PHONE>', 'send_way' => '1', 'content' =>"$subject", 'send_time' => '');    $result =$client->call('deliver',$param);  print_r($result); ?> [root@HEBGAT05 ~]#  
邮件相关内容 <?php $host = '10.4.64.106'; $database = 'zabbix'; $username = 'root'; $password = 'Wyzx@415'; $connection = mysql_connect($host,$username, $password);//连接到数据库 mysql_query("set names'utf8'");//编码转化 if (!$connection) {  die("could not connect to the database.\n" . mysql_error());//诊断连接错误 } $selectedDb = mysql_select_db($database);//选择数据库 if (!$selectedDb) {  die("could not to the database\n" . mysql_error()); } //$query = "select subject  from alerts   where sendto='13073100823'   orderby eventid desc  LIMIT 1";//构建查询语句 $query = "select subject,message  from alerts   where sendto='13073100823' and  FROM_UNIXTIME(clock, '%Y-%m-%d %H:%i:%S')>=date_sub(NOW(),interval1000 minute) order by eventid desc  LIMIT1";//构建查询语句  
$result = mysql_query($query);//执行查询 if (!$result) {  die("could not to the database\n" . mysql_error()); } while ($row = mysql_fetch_row($result)) {   //取出结果并显示  $subject = $row[0];  $message = $row[1];  echo "\n"; } mysql_close($connection); include('nusoap.php');  
 $client = newnusoap_client('http://10.4.64.52:8081/services/SmcService?wsdl','wsdl');  $err = $client->getError();   if($err) {      echo '<h2>Constructor error</h2><pre>' . $err .'</pre>';   } $client ->soap_defencoding =  'utf-8' ; $client ->decode_utf8 = false; $client ->xml_encoding =  'utf-8' ; $param = array( 'username' => '1', 'password' => 'c4ca4238a0b923820dcc509a6f75849b',  'src_id' => '8888', 'level' => '1', 'title' => "$subject", 'content' => "$message", 'attachmentfile' => '', 'attachment' => '', 'send_time' => '');   $result = $client->call('deliverEmail',$param);  print_r ($result); ?> 相关修改: 1、连接数据库的用户名密码,此数据库为部署短信网关连接的数据库 2、  $query = "select subject from alerts    wheresendto='13073100823'   order by eventiddesc  LIMIT 1";//构建查询语句 这里的sendto 是添加用户的示警媒介的号码添加用户时输入的手机号 3、$client = new nusoap_client('h :8081/services/SmcService?wsdl','wsdl');这里需要改成自己的短信网关服务地址 4、'src_id' => '8888', 'level' => '1', 'to_users' => '<PHONE>13073100823</PHONE>', 这里是要接收短信的手机号码 5、拷贝文件nusoap-0.9.5到系统并解压经nusoap.php放到/usr/local/php/lib/php/  
短信网关WEBservice接口 
 http://localhost:8081/services/SmcService?wsdl 你们和我的环境有所区别,因为你们的是虚拟机的,可能会有啥别的问题,有问题再讨论吧,但应该是没啥问题  
大工高成,配置好触发器,有告警就会给你发短信的 可以监控 程序端口 程序日志服务器主机情况等等 !!!  
给其他同事讲过,通过文档搭建失败的可以找我要视频教程哈!!!  
涉及mysql用户授权禁止登陆的问题时候需进行数据库登陆授权  
//设置密码 登录虚拟机内: mysql -uroot -pWyzx@415 use mysql  
UPDATE user SETPassword=PASSWORD(’Wyzx@415’) where USER=’root’; grant all privileges on*.* to ‘root’@’%’ identified by ‘Wyzx@415’ with grant option; (注意此处复制到系统内执行时候如果报错的话需要切换到英文模式下把‘’改下) //更新权限 flush privileges; exit 退出数据库 重新启动mysql: service mysqld start  
原创:wikowin  
 
 |