Hi
I try to make my Zabbix to send sms meesages.
I am trying this manual:
http://www.zabbix.com/wiki/howto/config/alerts/smsapi
But when I'm trying to run script I get this error:
What I am doing wrong?
This is cli_sms_clickatell.php config:
I try to make my Zabbix to send sms meesages.
I am trying this manual:
http://www.zabbix.com/wiki/howto/config/alerts/smsapi
But when I'm trying to run script I get this error:
root@ht-50814ffc17b2c:/etc/zabbix/alert.d# ./cli_sms_clickatell.php +48793383812 "Test subject" "Test message"
PHP Warning: file_put_contents(/var/log/zabbix-server/sms/sms_alert_clockwork_20121107181215): failed to open stream: No such file or directory in /etc/zabbix/alert.d/cli_sms_clickatell.php on line 53
PHP Fatal error: Call to undefined function curl_init() in /etc/zabbix/alert.d/cli_sms_clickatell.php on line 115
root@ht-50814ffc17b2c:/etc/zabbix/alert.d#
PHP Warning: file_put_contents(/var/log/zabbix-server/sms/sms_alert_clockwork_20121107181215): failed to open stream: No such file or directory in /etc/zabbix/alert.d/cli_sms_clickatell.php on line 53
PHP Fatal error: Call to undefined function curl_init() in /etc/zabbix/alert.d/cli_sms_clickatell.php on line 115
root@ht-50814ffc17b2c:/etc/zabbix/alert.d#
This is cli_sms_clickatell.php config:
#!/usr/bin/php
<?php
/*****************************************
* cli_sms.php
*
* A simple script to send an SMS via various SMS gateways' HTTP APIs.
*
* Version History:
*
* v0.1 2007-09-11 - zabbix wiki user 'rts'
* v0.2 2010-07-08 - Walter Heck <walter AT tribily DOT com>
* v0.3 2012-02-06 . Jyri-Petteri Paloposki <[email protected]>
* * Support for Nexmo and BudgetSMS (previously only Clickatell)
* v0.4 2012-04-12 - Martin Steel <[email protected]>
* * Support for mediaburst (customer request)
* v0.5 2012-07-19 - Caleb Wong <[email protected]>
* * Support the "Clickatell" API with "concat" which can be define how many SMS can be send in 1 action(line 68), official recommended length is 3.
* v0.6 2012-10-25 - Martin Steel <[email protected]>
* * Replaced mediaburst with Clockwork to fit in with Mediaburst product changes
*
*****************************************/
// The service you're using. Choices include clickatell, budgetsms, nexmo and clockwork
$service = 'clockwork';
// The API key.
$apikey = "";
// Username and password. With BudgetSMS use userid as password. Username not needed for Nexmo or Clockwork
$user = "myuserfromclicatell";
$password = "mypasswordfromclicatel";
// The sender name / number. This has to conform to your service provider's
//+regulations.
$from = "Zabbix";
// Where should this script log to? The directory must already exist.
$logfilelocation = "/var/log/zabbix-server/sms/";
// if debug is true, log files will be generated
$debug = true;
/************************************************** ********************
!! Do not change anything below this line unless
you _really_ know what you are doing !!
************************************************** ********************/
if (count($argv)<3) {
die ("Usage: ".$argv[0]." recipientmobilenumber \"subject\" \"message\"\n");
}
if ( $debug )
file_put_contents($logfilelocation."sms_alert_" . $service . "_".date("YmdHis"), serialize($argv));
$to = $argv[1];
$subject = $argv[2];
$message = $argv[3];
$text = $subject.": ".$message;
switch ($service) {
case 'clickatell':
$apiargs = array(
"api_id" => $apikey,
"user" => $user,
"password" => $password,
"to" => $to,
"text" => $text,
"from" => $from,
"concat" => '3',
);
$baseurl = "http://api.clickatell.com/http/sendmsg";
break;
case 'budgetsms':
$apiargs = array(
"handle" => $apikey,
"username" => $user,
"userid" => $password,
"to" => $to,
"msg" => $text,
"from" => $from,
);
$baseurl = 'http://www.budgetsms.net/api/sendsms';
break;
case 'nexmo':
$apiargs = array(
"username" => $apikey,
"password" => $password,
"to" => $to,
"text" => $text,
"from" => $from,
);
$baseurl = 'http://rest.nexmo.com/sms/json';
break;
case 'clockwork':
$apiargs = array(
"key" => $apikey,
"to" => $to,
"content" => $text,
"from" => $from,
);
$baseurl = 'https://api.clockworksms.com/http/send';
}
$params = "";
foreach ($apiargs as $k=>$v) {
if ( $params != "" ) {
$params .= "&";
}
$params .= $k."=".urlencode($v);
}
$url = $baseurl . '?' . $params;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url );
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
if ( $result === false ) {
file_put_contents($logfilelocation."sms_alert_" . $service . "_error_".date("YmdHis"), curl_error($curl));
die(curl_error($curl)."\n");
} else {
if ( $debug || $result != 100 )
file_put_contents($logfilelocation."sms_alert_" . $service . "_answer_".date("YmdHis"), $result);
}
<?php
/*****************************************
* cli_sms.php
*
* A simple script to send an SMS via various SMS gateways' HTTP APIs.
*
* Version History:
*
* v0.1 2007-09-11 - zabbix wiki user 'rts'
* v0.2 2010-07-08 - Walter Heck <walter AT tribily DOT com>
* v0.3 2012-02-06 . Jyri-Petteri Paloposki <[email protected]>
* * Support for Nexmo and BudgetSMS (previously only Clickatell)
* v0.4 2012-04-12 - Martin Steel <[email protected]>
* * Support for mediaburst (customer request)
* v0.5 2012-07-19 - Caleb Wong <[email protected]>
* * Support the "Clickatell" API with "concat" which can be define how many SMS can be send in 1 action(line 68), official recommended length is 3.
* v0.6 2012-10-25 - Martin Steel <[email protected]>
* * Replaced mediaburst with Clockwork to fit in with Mediaburst product changes
*
*****************************************/
// The service you're using. Choices include clickatell, budgetsms, nexmo and clockwork
$service = 'clockwork';
// The API key.
$apikey = "";
// Username and password. With BudgetSMS use userid as password. Username not needed for Nexmo or Clockwork
$user = "myuserfromclicatell";
$password = "mypasswordfromclicatel";
// The sender name / number. This has to conform to your service provider's
//+regulations.
$from = "Zabbix";
// Where should this script log to? The directory must already exist.
$logfilelocation = "/var/log/zabbix-server/sms/";
// if debug is true, log files will be generated
$debug = true;
/************************************************** ********************
!! Do not change anything below this line unless
you _really_ know what you are doing !!
************************************************** ********************/
if (count($argv)<3) {
die ("Usage: ".$argv[0]." recipientmobilenumber \"subject\" \"message\"\n");
}
if ( $debug )
file_put_contents($logfilelocation."sms_alert_" . $service . "_".date("YmdHis"), serialize($argv));
$to = $argv[1];
$subject = $argv[2];
$message = $argv[3];
$text = $subject.": ".$message;
switch ($service) {
case 'clickatell':
$apiargs = array(
"api_id" => $apikey,
"user" => $user,
"password" => $password,
"to" => $to,
"text" => $text,
"from" => $from,
"concat" => '3',
);
$baseurl = "http://api.clickatell.com/http/sendmsg";
break;
case 'budgetsms':
$apiargs = array(
"handle" => $apikey,
"username" => $user,
"userid" => $password,
"to" => $to,
"msg" => $text,
"from" => $from,
);
$baseurl = 'http://www.budgetsms.net/api/sendsms';
break;
case 'nexmo':
$apiargs = array(
"username" => $apikey,
"password" => $password,
"to" => $to,
"text" => $text,
"from" => $from,
);
$baseurl = 'http://rest.nexmo.com/sms/json';
break;
case 'clockwork':
$apiargs = array(
"key" => $apikey,
"to" => $to,
"content" => $text,
"from" => $from,
);
$baseurl = 'https://api.clockworksms.com/http/send';
}
$params = "";
foreach ($apiargs as $k=>$v) {
if ( $params != "" ) {
$params .= "&";
}
$params .= $k."=".urlencode($v);
}
$url = $baseurl . '?' . $params;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url );
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
if ( $result === false ) {
file_put_contents($logfilelocation."sms_alert_" . $service . "_error_".date("YmdHis"), curl_error($curl));
die(curl_error($curl)."\n");
} else {
if ( $debug || $result != 100 )
file_put_contents($logfilelocation."sms_alert_" . $service . "_answer_".date("YmdHis"), $result);
}
Comment