[Python] How to retrive Macros Value of a host from nagios core?

Discussão em 'Python' iniciado por Stack, Janeiro 31, 2025.

  1. Stack

    Stack Membro Participativo

    I have a Nagios-core server for monitoring my network and I want to configure an alert via sms but the problem is the sms gateway is on another host,
    my idea is to retrieve the macro's value of the hosts and send it to the sms gateway.

    Not: The sms gateway used is Gammu.

    I create a command-line on the Nagios server but it doesn't work :

    the command line contains a full path of the script notify_BY-SMS.sh

    define command{
    command_name notify-host-by-sms
    command_line /usr/local/nagios/libexec/notify_BY-SMS.sh

    }


    the script notify_BY-SMS.sh is described below:

    #!/bin/bash


    I try to retrieve the $HOSTNAME$ $HOSTSTATE$ Macros from Nagios and set it on a variable named $message :

    message=$(/usr/bin/printf "%b" "Alert $HOSTNAME$ is $HOSTSTATE$")


    retrieve the $CONTACTPAGER$ macros and set it on a variable named $contact :

    contact=$(/usr/bin/printf "%b" $CONTACTPAGER$)


    connect to MySQL users remotely centreon :

    mysql -h 192.X.Y.Z -u centreon -D smsd --password=<PASSWORD>


    and I try to insert the variable sets INTO the Gammu outbox table :

    -e "INSERT INTO outbox (\`CreatorID\`, \`SenderID\`, \`DeliveryReport\`, \`MultiPart\`, \`InsertIntoDB\`, \`Text\`, \`DestinationNumber\`, \`RelativeValidity\`, \`Coding\`, \`UDH\`, \`Class\`, \`TextDecoded\`) VALUES ('Gammu 1.41.0', '2', 'default', 'FALSE', NOW(), '', '$contact', 255, 'Default_No_Compression', '', -1, '$message');"

    Continue reading...

Compartilhe esta Página