Fix coding style part 2

This commit is contained in:
Job Snijders
2015-07-14 17:41:54 +02:00
parent ad9590df9b
commit 361653aa81
731 changed files with 37529 additions and 33991 deletions
+26 -24
View File
@@ -1,14 +1,16 @@
<?php
/* Copyright (C) 2014 Daniel Preussker <f0o@devilcode.org>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
@@ -22,27 +24,27 @@
*/
foreach( $opts as $method=>$apis ) {
// var_dump($method); //FIXME: propper debuging
foreach( $apis as $api ) {
// var_dump($api); //FIXME: propper debuging
list($host, $api) = explode("?",$api,2);
foreach( $obj as $k=>$v ) {
$api = str_replace("%".$k,$method == "get" ? urlencode($v) : $v, $api);
}
// var_dump($api); //FIXME: propper debuging
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, ($method == "get" ? $host."?".$api : $host) );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, strtoupper($method));
curl_setopt($curl, CURLOPT_POSTFIELDS, $api);
$ret = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if( $code != 200 ) {
var_dump("API '$host' returned Error"); //FIXME: propper debuging
var_dump("Params: ".$api); //FIXME: propper debuging
var_dump("Return: ".$ret); //FIXME: propper debuging
return false;
}
}
// var_dump($method); //FIXME: propper debuging
foreach( $apis as $api ) {
// var_dump($api); //FIXME: propper debuging
list($host, $api) = explode("?",$api,2);
foreach( $obj as $k=>$v ) {
$api = str_replace("%".$k,$method == "get" ? urlencode($v) : $v, $api);
}
// var_dump($api); //FIXME: propper debuging
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, ($method == "get" ? $host."?".$api : $host) );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, strtoupper($method));
curl_setopt($curl, CURLOPT_POSTFIELDS, $api);
$ret = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if( $code != 200 ) {
var_dump("API '$host' returned Error"); //FIXME: propper debuging
var_dump("Params: ".$api); //FIXME: propper debuging
var_dump("Return: ".$ret); //FIXME: propper debuging
return false;
}
}
}
return true;
+2 -2
View File
@@ -3,12 +3,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
+32 -28
View File
@@ -1,3 +1,5 @@
<?php
/* Copyright (C) 2014 Daniel Preussker <f0o@devilcode.org>, Tyler Christiansen <code@tylerc.me>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,34 +24,36 @@
*/
foreach($opts as $option) {
$url = $option['url'];
foreach($obj as $key=>$value) {
$api = str_replace("%".$key, $method == "get" ? urlencode($value) : $value, $api);
}
$curl = curl_init();
$data = array(
"message" => $obj["msg"],
"room_id" => $option["room_id"],
"from" => $option["from"],
"color" => $option["color"],
"notify" => $option["notify"],
"message_format" => $option["message_format"]
);
// Sane default of making the message color green if the message indicates
// that the alert recovered.
if(strpos($data["message"], "recovered")) { $data["color"] = "green"; }
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$ret = curl_exec($curl);
$url = $option['url'];
foreach($obj as $key=>$value) {
$api = str_replace("%".$key, $method == "get" ? urlencode($value) : $value, $api);
}
$curl = curl_init();
$data = array(
"message" => $obj["msg"],
"room_id" => $option["room_id"],
"from" => $option["from"],
"color" => $option["color"],
"notify" => $option["notify"],
"message_format" => $option["message_format"]
);
// Sane default of making the message color green if the message indicates
// that the alert recovered.
if(strstr($data["message"], "recovered")) {
$data["color"] = "green";
}
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$ret = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if($code != 200) {
var_dump("API '$url' returned Error");
var_dump("Params: " . $message);
var_dump("Return: " . $ret);
return false;
}
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if($code != 200) {
var_dump("API '$url' returned Error");
var_dump("Params: " . $message);
var_dump("Return: " . $ret);
return false;
}
}
return true;
+2 -2
View File
@@ -3,12 +3,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
+2 -2
View File
@@ -3,12 +3,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
+2 -2
View File
@@ -3,12 +3,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
+18 -14
View File
@@ -1,14 +1,16 @@
<?php
/* Copyright (C) 2015 Daniel Preussker <f0o@devilcode.org>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
@@ -22,20 +24,22 @@
*/
$protocol = array(
'service_key' => $opts,
'incident_key' => ($obj['id'] ? $obj['id'] : $obj['uid']),
'description' => ($obj['name'] ? $obj['name'].' on '.$obj['hostname'] : $obj['title']),
'client' => 'LibreNMS',
'service_key' => $opts,
'incident_key' => ($obj['id'] ? $obj['id'] : $obj['uid']),
'description' => ($obj['name'] ? $obj['name'].' on '.$obj['hostname'] : $obj['title']),
'client' => 'LibreNMS',
);
if( $obj['state'] == 0 ) {
$protocol['event_type'] = 'resolve';
} elseif( $obj['state'] == 2 ) {
$protocol['event_type'] = 'acknowledge';
} else {
$protocol['event_type'] = 'trigger';
$protocol['event_type'] = 'resolve';
}
elseif( $obj['state'] == 2 ) {
$protocol['event_type'] = 'acknowledge';
}
else {
$protocol['event_type'] = 'trigger';
}
foreach( $obj['faults'] as $fault=>$data ) {
$protocol['details'][] = $data['string'];
$protocol['details'][] = $data['string'];
}
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://events.pagerduty.com/generic/2010-04-15/create_event.json' );
@@ -45,7 +49,7 @@ curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($protocol));
$ret = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if( $code != 200 ) {
var_dump("PagerDuty returned Error, retry later"); //FIXME: propper debuging
return false;
var_dump("PagerDuty returned Error, retry later"); //FIXME: propper debuging
return false;
}
return true;
+33 -31
View File
@@ -1,28 +1,30 @@
<?php
/* Copyright (C) 2015 James Campbell <neokjames@gmail.com>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Copyright (C) 2015 Daniel Preussker <f0o@devilcode.org>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
@@ -40,34 +42,34 @@ foreach( $opts as $api ) {
$data['token'] = $api['appkey'];
$data['user'] = $api['userkey'];
switch( $obj['severity'] ) {
case "critical":
$severity = "Critical";
$data['priority'] = 1;
if( !empty( $api['sound_critical'] ) ) {
$data['sound'] = $api['sound_critical'];
}
break;
case "warning":
$severity = "Warning";
$data['priority'] = 0;
if( !empty( $api['sound_warning'] ) ) {
$data['sound'] = $api['sound_warning'];
}
break;
case "critical":
$severity = "Critical";
$data['priority'] = 1;
if( !empty( $api['sound_critical'] ) ) {
$data['sound'] = $api['sound_critical'];
}
break;
case "warning":
$severity = "Warning";
$data['priority'] = 0;
if( !empty( $api['sound_warning'] ) ) {
$data['sound'] = $api['sound_warning'];
}
break;
}
switch( $obj['state'] ) {
case 0:
$title_text = "OK";
if( !empty( $api['sound_ok'] ) ) {
$data['sound'] = $api['sound_ok'];
}
break;
case 1:
$title_text = $severity;
break;
case 2:
$title_text = "Acknowledged";
break;
case 0:
$title_text = "OK";
if( !empty( $api['sound_ok'] ) ) {
$data['sound'] = $api['sound_ok'];
}
break;
case 1:
$title_text = $severity;
break;
case 2:
$title_text = "Acknowledged";
break;
}
$data['title'] = $title_text." - ".$obj['hostname']." - ".$obj['name'];
$message_text = "Timestamp: ".$obj['timestamp'];
+29 -27
View File
@@ -1,14 +1,16 @@
<?php
/* Copyright (C) 2014 Daniel Preussker <f0o@devilcode.org>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
@@ -22,30 +24,30 @@
*/
foreach( $opts as $tmp_api ) {
$host = $tmp_api['url'];
foreach( $obj as $k=>$v ) {
$api = str_replace("%".$k,$method == "get" ? urlencode($v) : $v, $api);
}
$curl = curl_init();
$data = array(
'text' => $obj['msg'],
'channel' => $tmp_api['channel'],
'username' => $tmp_api['username'],
'icon_url' => $tmp_api['icon_url'],
'icon_emoji' => $tmp_api['icon_emoji'],
);
$alert_message = "payload=" . json_encode($data);
curl_setopt($curl, CURLOPT_URL, $host);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST,true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $alert_message );
$ret = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if( $code != 200 ) {
var_dump("API '$host' returned Error"); //FIXME: propper debuging
var_dump("Params: ".$alert_message); //FIXME: propper debuging
var_dump("Return: ".$ret); //FIXME: propper debuging
return false;
}
$host = $tmp_api['url'];
foreach( $obj as $k=>$v ) {
$api = str_replace("%".$k,$method == "get" ? urlencode($v) : $v, $api);
}
$curl = curl_init();
$data = array(
'text' => $obj['msg'],
'channel' => $tmp_api['channel'],
'username' => $tmp_api['username'],
'icon_url' => $tmp_api['icon_url'],
'icon_emoji' => $tmp_api['icon_emoji'],
);
$alert_message = "payload=" . json_encode($data);
curl_setopt($curl, CURLOPT_URL, $host);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST,true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $alert_message );
$ret = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if( $code != 200 ) {
var_dump("API '$host' returned Error"); //FIXME: propper debuging
var_dump("Params: ".$alert_message); //FIXME: propper debuging
var_dump("Return: ".$ret); //FIXME: propper debuging
return false;
}
}
return true;