Subversion Repositories alarming

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 daniel-mar 1
#!/usr/bin/php
2
<?php
3
 
4
# --- PLEASE MODIFY:
5
 
6
# To which daemon server should the alarm be sent?
7
$url     = "http://127.0.0.1:8085";
8
 
9
# Which targets should be reported?
10
$targets = array(
11
	"1.3.6.1.4.1.37476.2.4.2.0",    // Any
12
	"1.3.6.1.4.1.37476.2.4.2.1002", // Motion, camera
13
	"1.3.6.1.4.1.37476.1.2.1.1"     // PRIVATE: Webcam of Daniel Marschall
14
);
15
 
16
# --- DON'T MODIFY AFTER THIS LINE
17
 
18
$fields = array();
19
$fields[] = "action=server_alert"; // 1.3.6.1.4.1.37476.2.4.1.2
20
foreach ($targets as $target) {
21
	// Note: We are not using http_build_query(), because it sends targets[0]=...&targets[1]=...,
22
	// which is not what we need. We want targets=...&targets=...
23
	$fields[] = "targets=".urlencode($target);
24
}
25
$fields_string = implode('&', $fields);
26
 
27
echo urldecode($fields_string)."\n";
28
 
29
$ch = curl_init();
30
curl_setopt($ch, CURLOPT_URL, $url);
31
curl_setopt($ch, CURLOPT_POST, true);
32
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
33
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
34
 
35
$result = curl_exec($ch);
36
 
37
echo $result;
38
 
39
// Note: We are not using Python to send the alert, because the "import" command is extremely
40
// slow, and we need to send an alarm withhin milliseconds!
41
/*
42
import requests
43
d = {"action": "server_alert", "targets": [
44
	"...",
45
	"..."
46
]}
47
requests.post("http://127.0.0.1:8085", data=d)
48
*/