forked from phpipam/php-snmptraps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
traphandler.php
executable file
·64 lines (47 loc) · 1.46 KB
/
traphandler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/**
* php traphandler for snmp traps
*
* set configuration parameters under functions/config.php
*
* @author: Miha Petkovsek <[email protected]>
*
* example trap:
* snmptrap -v 2c -c public 10.12.50.51 '' .1.3.6.1.4.1.5089.1.0.1 .1.3.6.1.4.1.5089.2.0.999 s "123456"
*
**/
# include config and trap class
require( dirname(__FILE__) . '/functions/classes/class.Database.php' );
require( dirname(__FILE__) . '/functions/classes/class.Result.php' );
require( dirname(__FILE__) . '/functions/classes/class.Notify.php' );
require( dirname(__FILE__) . '/functions/classes/class.traphandler.php' );
require( dirname(__FILE__) . '/config.php' );
# --- process
# get data from stdin
while($f = fgets(STDIN)){
$trap_content[] = $f;
}
# --- load traphandler and process provided trap
$Trap = new Trap ($trap_content);
# --- write file
if ($filename!==false) {
$File = new Trap_file ($Trap->get_trap_details ());
// set where to write
$File->set_file ($filename);
// write raw file
// $Trap->write_file ();
// write parsed file
$File->write_file_parsed ();
}
# --- write to database
$Trap->write_trap ();
# --- send notification
if ($notification_methods !== false && $Trap->exception === false) {
// load object and send trap
$Notify = new Trap_notify ($Trap->get_trap_details (), $notification_params, $filename);
// send
$Notify->send_notification ();
}
# --- close connaection and file
$File->close_file ();
?>