Twilio integration

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
SavaSC
Posts: 238
Joined: Wed Feb 23, 2011 4:49 pm

Twilio integration

Post by SavaSC »

Hello,

Since Nagios uses e-mail for notifications then if email goes down, no notifications. We are trying to get around this using a combination of Nagios' built-in notification system and Twilio. Unfortunately, while I have found a couple of things that claim to get Twilio to work with Nagios, none of them are functioning for me.

Does anyone have a working system with Nagios/Twilio that can tell me how they did it?

Thanks!
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Twilio integration

Post by rkennedy »

Have you seen this plugin on our Exchange? It links to the authors website which has some pretty well written instructions -
https://exchange.nagios.org/directory/T ... io/details
Former Nagios Employee
SavaSC
Posts: 238
Joined: Wed Feb 23, 2011 4:49 pm

Re: Twilio integration

Post by SavaSC »

I saw it, but couldn't get it going. I'll take another look to see if I can find what I goobered up.
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Twilio integration

Post by rkennedy »

It looks like someone mentioned it still works two weeks back, so I assume it should be working.

It should be just getting the API to communicate, let us know if you run into issues and what the problem(s) are, and we can probably help you through.
Former Nagios Employee
SavaSC
Posts: 238
Joined: Wed Feb 23, 2011 4:49 pm

Re: Twilio integration

Post by SavaSC »

I'm still not able to get a text to come through. Here is my setup.

I put the twilio-php folder and the sendTxtMsg.php in the /usr/local/etc folder. I did edit the sendTxtMsg.php file to reflect my $sid, $token, & $twilio_number.

I have created the commands in Nagios. Here they are:

Code: Select all

define command{
    command_name    notify-host-by-txt
    command_line    /usr/bin/php /usr/local/etc/sendTxtMsg.php "$CONTACTPAGER$" "Nagios Alert\nType: $NOTIFICATIONTYPE$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\nWhen: $LONGDATETIME$"
}

define command{
    command_name    notify-service-by-txt
    command_line    /usr/bin/php /usr/local/etc/sendTxtMsg.php "$CONTACTPAGER$" "Nagios Alert\nType: $NOTIFICATIONTYPE$\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\nWhen: $LONGDATETIME$"
}
I created a contact with my cell phone number (including the "1" in front). Under Alert Settings -> Manage Host Notification Commands I added notify-host-by-txt to the user.

I created a Host record for a desktop and added the new contact to the Manage Contacts section. I set the Check & Retry intervals to "1" as well as the Max Check Attempts. Also, notification interval is set to "1".

If I turn off the desktop I wait 5 minutes but still get no text. Nagios sees it as down, no problem. No text.

Any suggestions about what I might have done wrong?
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Twilio integration

Post by rkennedy »

SavaSC wrote:I'm still not able to get a text to come through. Here is my setup.

I put the twilio-php folder and the sendTxtMsg.php in the /usr/local/etc folder. I did edit the sendTxtMsg.php file to reflect my $sid, $token, & $twilio_number.

I have created the commands in Nagios. Here they are:

Code: Select all

define command{
    command_name    notify-host-by-txt
    command_line    /usr/bin/php /usr/local/etc/sendTxtMsg.php "$CONTACTPAGER$" "Nagios Alert\nType: $NOTIFICATIONTYPE$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\nWhen: $LONGDATETIME$"
}

define command{
    command_name    notify-service-by-txt
    command_line    /usr/bin/php /usr/local/etc/sendTxtMsg.php "$CONTACTPAGER$" "Nagios Alert\nType: $NOTIFICATIONTYPE$\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\nWhen: $LONGDATETIME$"
}
I created a contact with my cell phone number (including the "1" in front). Under Alert Settings -> Manage Host Notification Commands I added notify-host-by-txt to the user.

I created a Host record for a desktop and added the new contact to the Manage Contacts section. I set the Check & Retry intervals to "1" as well as the Max Check Attempts. Also, notification interval is set to "1".

If I turn off the desktop I wait 5 minutes but still get no text. Nagios sees it as down, no problem. No text.

Any suggestions about what I might have done wrong?
From Nagios - does it show that it executed the Notification? I'd like to verify the actual plugin works first off.

Let's try to test the script from the CLI. Can you manually execute it (as the nagios user)? This should work -

Code: Select all

/usr/bin/php /usr/local/etc/sendTxtMsg.php "1yournumber" "test message"
If that doesn't work, check the permissions on the file, and make sure it's executable. Let us know how it goes!
Former Nagios Employee
SavaSC
Posts: 238
Joined: Wed Feb 23, 2011 4:49 pm

Re: Twilio integration

Post by SavaSC »

When you say the CLI, do you mean the Linux CLI or the Nagios-CLI plug-in? I don't, currently, have the Nagios-CLI installed. Do I need to?
User avatar
hsmith
Agent Smith
Posts: 3539
Joined: Thu Jul 30, 2015 11:09 am
Location: 127.0.0.1
Contact:

Re: Twilio integration

Post by hsmith »

The linux terminal.
Former Nagios Employee.
me.
SavaSC
Posts: 238
Joined: Wed Feb 23, 2011 4:49 pm

Re: Twilio integration

Post by SavaSC »

It looks like we have a cert issue, to start with. Our cert guy is out for a couple of days, so I'll have to wait until he gets back to address that part. Here is the output:

Code: Select all

object(Services_Twilio_TinyHttpException)#21 (7) {
  ["message:protected"]=>
  string(146) "SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed"
  ["string:private"]=>
  string(0) ""
  ["code:protected"]=>
  int(0)
  ["file:protected"]=>
  string(54) "/usr/local/etc/twilio-php/Services/Twilio/TinyHttp.php"
  ["line:protected"]=>
  int(84)
  ["trace:private"]=>
  array(8) {
    [0]=>
    array(4) {
      ["function"]=>
      string(6) "__call"
      ["class"]=>
      string(24) "Services_Twilio_TinyHttp"
      ["type"]=>
      string(2) "->"
      ["args"]=>
      array(3) {
        [0]=>
        string(73) "/2010-04-01/Accounts/ACddc2ea17353f8d41ac45adcf66d3aad9/SMS/Messages.json"
        [1]=>
        array(1) {
          ["Content-Type"]=>
          string(33) "application/x-www-form-urlencoded"
        }
        [2]=>
        string(48) "From=18324161073&To=18323704569&Body=TestMessage"
      }
    }
    [1]=>
    array(6) {
      ["file"]=>
      string(45) "/usr/local/etc/twilio-php/Services/Twilio.php"
      ["line"]=>
      int(115)
      ["function"]=>
      string(4) "post"
      ["class"]=>
      string(24) "Services_Twilio_TinyHttp"
      ["type"]=>
      string(2) "->"
      ["args"]=>
      array(2) {
        [0]=>
        string(56) "Accounts/ACddc2ea17353f8d41ac45adcf66d3aad9/SMS/Messages"
        [1]=>
        array(3) {
          ["From"]=>
          string(11) "18324161073"
          ["To"]=>
          string(11) "18323704569"
          ["Body"]=>
          string(11) "TestMessage"
        }
      }
    }
    [2]=>
    array(6) {
      ["file"]=>
      string(58) "/usr/local/etc/twilio-php/Services/Twilio/ListResource.php"
      ["line"]=>
      int(89)
      ["function"]=>
      string(10) "createData"
      ["class"]=>
      string(15) "Services_Twilio"
      ["type"]=>
      string(2) "->"
      ["args"]=>
      array(2) {
        [0]=>
        string(47) "ACddc2ea17353f8d41ac45adcf66d3aad9/SMS/Messages"
        [1]=>
        array(3) {
          ["From"]=>
          string(11) "18324161073"
          ["To"]=>
          string(11) "18323704569"
          ["Body"]=>
          string(11) "TestMessage"
        }
      }
    }
    [3]=>
    array(6) {
      ["file"]=>
      string(62) "/usr/local/etc/twilio-php/Services/Twilio/CachingDataProxy.php"
      ["line"]=>
      int(115)
      ["function"]=>
      string(10) "createData"
      ["class"]=>
      string(28) "Services_Twilio_ListResource"
      ["type"]=>
      string(2) "->"
      ["args"]=>
      array(2) {
        [0]=>
        string(12) "SMS/Messages"
        [1]=>
        array(3) {
          ["From"]=>
          string(11) "18324161073"
          ["To"]=>
          string(11) "18323704569"
          ["Body"]=>
          string(11) "TestMessage"
        }
      }
    }
    [4]=>
    array(6) {
      ["file"]=>
      string(54) "/usr/local/etc/twilio-php/Services/Twilio/Resource.php"
      ["line"]=>
      int(44)
      ["function"]=>
      string(10) "createData"
      ["class"]=>
      string(32) "Services_Twilio_CachingDataProxy"
      ["type"]=>
      string(2) "->"
      ["args"]=>
      array(2) {
        [0]=>
        string(12) "SMS/Messages"
        [1]=>
        array(3) {
          ["From"]=>
          string(11) "18324161073"
          ["To"]=>
          string(11) "18323704569"
          ["Body"]=>
          string(11) "TestMessage"
        }
      }
    }
    [5]=>
    array(6) {
      ["file"]=>
      string(58) "/usr/local/etc/twilio-php/Services/Twilio/ListResource.php"
      ["line"]=>
      int(59)
      ["function"]=>
      string(10) "createData"
      ["class"]=>
      string(24) "Services_Twilio_Resource"
      ["type"]=>
      string(2) "->"
      ["args"]=>
      array(1) {
        [0]=>
        array(3) {
          ["From"]=>
          string(11) "18324161073"
          ["To"]=>
          string(11) "18323704569"
          ["Body"]=>
          string(11) "TestMessage"
        }
      }
    }
    [6]=>
    array(6) {
      ["file"]=>
      string(62) "/usr/local/etc/twilio-php/Services/Twilio/Rest/SmsMessages.php"
      ["line"]=>
      int(22)
      ["function"]=>
      string(7) "_create"
      ["class"]=>
      string(28) "Services_Twilio_ListResource"
      ["type"]=>
      string(2) "->"
      ["args"]=>
      array(3) {
        [0]=>
        string(11) "18324161073"
        [1]=>
        string(11) "18323704569"
        [2]=>
        string(11) "TestMessage"
      }
    }
    [7]=>
    array(5) {
      ["file"]=>
      string(29) "/usr/local/etc/sendTxtMsg.php"
      ["line"]=>
      int(26)
      ["function"]=>
      string(6) "create"
      ["class"]=>
      string(32) "Services_Twilio_Rest_SmsMessages"
      ["type"]=>
      string(2) "->"
    }
  }
  ["severity:protected"]=>
  int(1)
}
Until he gets back, any suggestions?
Last edited by mcapra on Fri Jun 10, 2016 1:11 pm, edited 1 time in total.
Reason: please wrap long/technical outputs in [code] tags
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Twilio integration

Post by rkennedy »

It looks like the plugin includes an SSL certificate (which I assume is for Twilio's server). https://github.com/JustinCarmony/Nagios ... ficate.crt

They may have updated their cert, which is why you are seeing the error. I checked the certificate for api.twilio.com and it came back as this, so you might be able to replace that file with what I've pasted below -

Code: Select all

-----BEGIN CERTIFICATE-----
MIIFvTCCBKWgAwIBAgIQKBylVBf65NqvZJKMbeWFUDANBgkqhkiG9w0BAQsFADBB
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMdGhhd3R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