Skip to content

Commit 7339ed3

Browse files
author
Jack Lu
committed
Add HTTP web hook alert.
1 parent fe15522 commit 7339ed3

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

alerts.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,37 @@ function alert_sms_twilio($data, $context) {
9393
}
9494
}
9595

96+
/*
97+
* Notifies a web hook over HTTP regarding alert.
98+
* All context parameters are sent, via GET.
99+
*
100+
* data['url']: the target web hook
101+
* context: encoded as GET parameters
102+
*/
103+
function alert_http($data, $context) {
104+
if(!isset($data['url'])) {
105+
die("alert_http: missing url\n");
106+
}
107+
108+
$url = $data['url'] . '?';
109+
$first = true;
110+
111+
foreach($context as $k => $v) {
112+
if($first) {
113+
$first = false;
114+
} else {
115+
$url .= '&';
116+
}
117+
118+
$url .= urlencode($k) . '=' . urlencode($v);
119+
}
120+
121+
require_once('checks.php');
122+
$result = check_http_helper(array('url' => $url));
123+
124+
if($result['status'] == 'fail' && isset($result['message'])) {
125+
echo "alert_http: error: {$result['message']}\n";
126+
}
127+
}
128+
96129
?>

0 commit comments

Comments
 (0)