King Carter
King Carter

Reputation: 1

Python custom alertscript in zabbix doesn't work properly

I would like to set sending SMS notifications by python script, but I have one problem with this. I am trying according this manual https://www.zabbix.com/documentation/current/en/manual/config/notifications/media/script . The script does execute but it doesn't send values which I want, it sends the parameters that are set up on the Zabbix server. This is my script:

import logging
import sys
import pandas as pd



import smpplib.gsm
import smpplib.client
import smpplib.consts



hostname = sys.argv[1]

eventname = sys.argv[2]

severity = sys.argv[3]



#if you want to know what's happening
logging.basicConfig(level='DEBUG')



# Two parts, GSM default / UCS2, SMS with UDH
parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(u'')



client = smpplib.client.Client('smpp server ip ', example port)



# Print when obtain message_id
client.set_message_sent_handler(
    lambda pdu: sys.stdout.write('sent {} {}\n'.format(pdu.sequence, pdu.message_id)))



# Handle delivery receipts (and any MO SMS)
def handle_deliver_sm(pdu):
        sys.stdout.write('delivered {}\n'.format(pdu.receipted_message_id))
        return 0 # cmd status for deliver_sm_resp



client.set_message_received_handler(lambda pdu: handle_deliver_sm(pdu))



client.connect()
client.bind_transceiver(system_id='Example', password='Example@2023')



for part in parts:
        # Use command-line arguments for destination phone number and message content
        dest_phone = sys.argv[0]
        short_message = "{}: {}".format(sys.argv[1], sys.argv[2])

        pdu = client.send_message(
            source_addr_ton=smpplib.consts.SMPP_TON_ALNUM,
            source_addr_npi=smpplib.consts.SMPP_NPI_UNK,
            # Make sure it is a byte string, not unicode:
            source_addr='27840001019',



            dest_addr_ton=smpplib.consts.SMPP_TON_INTL,
            dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
            # Make sure these two params are byte strings, not unicode:
            destination_addr=dest_phone,
            short_message=short_message,



            data_coding=encoding_flag,
            esm_class=msg_type_flag,
            registered_delivery=True,
        )
        print(pdu.sequence)



# Enters a loop, waiting for incoming PDUs
client.listen()

In zabbix settings I have added these parmeters:

{HOST.NAME}
{ACTION.ID}
{ALERT.SENDTO}
{ALERT.SUBJECT}
{EVENT.SEVERITY}

Notificiations which have been sent from zabbix don't contain values only parameter names. Notificiations look like this:

{HOST.NAME},{EVENT.NAME},{EVENT.SEVERITY}

Can someone please help find the problem in my code?

I tried implementing cli arguments on my script so that I when I run the script I can pass the arguments but I still get the Zabbix Parameters as an SMS instead of the actual IP for example

Upvotes: 0

Views: 124

Answers (0)

Related Questions