Home > other >  Through ali cloud send SMS gateway zabbix monitoring alarm messages difficult situation
Through ali cloud send SMS gateway zabbix monitoring alarm messages difficult situation

Time:11-23

Unit within the server, switches, etc. Through the ZABBIX monitoring platform for monitoring management, configure the mail and WeChat can realize the alarm function, but in the configuration SMS alarm function when setbacks,
Python scripts manually trigger can receive SMS


Medium of zabbix alarm Settings


Zabbix server action events also show alarm information "has served"


But phones are no received messages, see ali cloud SMS platform, according to send information quantity does not increase, apparently not call ali platform interface to send SMS, but why zabbix server case shows that the alarm information "has served", which step the problem, is the interface code didn't write well?

O great god know,

Zabbix server, run the script in the following directory
/usr/lib/zabbix alertscripts/sendmail. Py

[root @ localhost alertscripts] # cat sendmail. Py
#! The/usr/bin/python
# - * - coding: utf-8 - * -
The import sys
The from aliyunsdkdysmsapi. Request. V20170525 import SendSmsRequest
The from aliyunsdkdysmsapi. Request. V20170525 import QuerySendDetailsRequest
The from aliyunsdkcore. Client import AcsClient
The import uuid
The from aliyunsdkcore. Profile import region_provider
The from aliyunsdkcore. HTTP import method_type as MT
The from aliyunsdkcore. HTTP import format_type as FT
The import json


Try:
Reload (sys)
Sys. Setdefaultencoding (' utf8)
Except NameError:
Pass
Except the Exception as err:
Raise err

# note: don't change
REGION="cn - hangzhou"
PRODUCT_NAME="Dysmsapi"
DOMAIN="dysmsapi.aliyuncs.com"

ACCESS_KEY_ID="ACCESS - ID #" ali cloud SMS registration ID
ACCESS_KEY_SECRET="ACCESS - the SECRET" # ali cloud message generated password

Acs_client=AcsClient (ACCESS_KEY_ID ACCESS_KEY_SECRET, REGION)
Region_provider. Add_endpoint (PRODUCT_NAME, REGION, DOMAIN)

Def send_sms (business_id, phone_numbers sign_name, template_code, template_param=None) :
SmsRequest=SendSmsRequest. SendSmsRequest ()
# application message template code, shall fill in
SmsRequest. Set_TemplateCode (template_code)

# message template variable parameter
If template_param is not None:
SmsRequest. Set_TemplateParam (template_param)

# set the business request serial number, mandatory,
SmsRequest. Set_OutId (business_id)

# message signature
SmsRequest. Set_SignName (sign_name)

# data submission
# smsRequest. Set_method (MT. POST)

# data submission format
# smsRequest. Set_accept_format (FT. JSON)

# text messaging number list, mandatory,
SmsRequest. Set_PhoneNumbers (phone_numbers)

# interface call SMS messages, return json
SmsResponse=acs_client. Do_action_with_exception (smsRequest)

# TODO business processing

Return smsResponse

If __name__=="__main__ ':
__business_id=uuid. Uuid1 ()
# print (__business_id)
SENDTO=STR (sys. Argv [1]) # from zabbix phone parameter
Message=STR (sys. Argv [2]) # from zabbix alarm message
Params={" message ": message}
Params=json. Dumps (params)
Print (send_sms (__business_id, SENDTO, "message signatures", "SMS_193519875 params))
  • Related