Login | ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/alarming/trunk/Server/doorbell/detect.d/client_alert
Revision: 6
Committed: Mon Jun 10 17:40:51 2019 UTC (3 years, 3 months ago) by daniel-marschall
File size: 1314 byte(s)
Log Message:
NEW: Doorbell listener

File Contents

# Content
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.2001", // Sound, doorbell
13 "1.3.6.1.4.1.37476.1.2.1.2" // PRIVATE: Doorbell 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 */

Properties

Name Value
svn:executable *