Ad Widget

Collapse

Zabbix 1.8 SMS alerts

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • simon_joerg
    Junior Member
    • May 2011
    • 1

    #1

    Zabbix 1.8 SMS alerts

    Hi

    I have been testing zabbix for the last coupple of days and must say im impressed by the ease of use, and configuration.

    However i have run into a issue that i cant seem to solve.
    One of the requirements for my company is that to have automated sms alerting.
    Due to this we on our old monitoring enviroment had a clickatell account which i would like to use for this purpose.

    After digging around in the forums and wiki i have come to a issue i cannot figure out how to solve.

    The setup is as follows:

    I have a python script on the server that hosts Zabbix.
    A action has been setup to send both email and sms message on any alert comming up.
    I know this works as the email is sent.

    The script looks like this


    #!/usr/bin/env python
    import urllib
    import sys

    #A non-overly complicated python interface to Clickatells.com's HTTP api.
    #Import into python, or use as shell script. Be sure to edit the default
    #parameters in the send function below

    def send(text, to = "{empty}", send_as = "{number to send from}", user = "{user id of my clickatell acc}", password = "{pass of my clickatell acc}", api_id = "{API id of clickatell acc}"):
    url = "http://api.clickatell.com/http/sendmsg"
    config = {}
    config['user'] = user
    config['password'] = password
    config['api_id'] = api_id
    config['from'] = send_as
    config['to'] = to
    config['text'] = text

    query = urllib.urlencode(config)
    file = urllib.urlopen(url, query)

    output = file.read()

    file.close()

    return output

    if __name__ == '__main__':
    argc = len(sys.argv)

    # first argument is the text message
    if argc == 2:
    print send(sys.argv[2])
    # arguments are a phone number followed by text
    elif argc == 3:
    print send(sys.argv[2], sys.argv[1])
    else:
    print 'Usage: sms.py [phone number] "Text message"'
    If i manually use the script it works
    For example:
    ./sms.py 12345678 "test"

    I have created a new media type and defined it as a script and pointed it to the sms.py script.
    The alert.d is defined in the zabbix_server.cfg file aswell.
    I have also added the media type to my account.

    When i generate a alarm i get a email.
    And if i check the /var/log/zabbix-server/zabbix-server
    i can see a entry saying "Usage: sms.py [phone number] "Text message""
    Which is from the script if its run without any variables.

    So my guess is the script works - the action works, but the media type is not passing the correct variables.

    How can i make the script pass the phone number taken from my account and the message from the action ?

    Thanks in advance

    Regards
    Simon Jorgensen
    Last edited by simon_joerg; 24-05-2011, 15:14.
  • Rudd
    Member
    • Mar 2011
    • 69

    #2
    Hi,

    I am not sure if it is the best way, but I have implemented that by configuring an Action with remote commands.

    Configuration -> Actions -> Create Action -> Action Operations -> New -> Operation type = Remote command.

    The remote command would look something like this:

    zabserver.mydomain.com:/usr/local/zabbix/bin/sms.py 61412345678 "{TRIGGER.NAME}: {ITEM.LASTVALUE}"

    hth,

    Comment

    Working...