forked from loadavg/loadavg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.Alert.php
executable file
·120 lines (84 loc) · 1.75 KB
/
class.Alert.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/**
* LoadAvg - Server Monitoring & Analytics
* http://www.loadavg.com
*
* Alert class
*
* @link https://github.com/loadavg/loadavg
* @author Karsten Becker
* @copyright 2014 Sputnik7
*
* This file is licensed under the Affero General Public License version 3 or
* later.
*/
class Alert
{
public static $alertDataArray;
public static $alertStatus;
public function __construct()
{
$alertDataArray = array();
$alertStatus = false;
}
/*
* setStatus - object knows if its active or not!
*/
public function setStatus( $status )
{
self::$alertStatus = $status;
}
/*
* setStatus - object knows if its active or not!
*/
public function getStatus( )
{
return self::$alertStatus;
}
/**
* initializeAlerts - initialize alert object
*
*/
public function initializeAlerts( )
{
if (isset(self::$alertDataArray))
unset(self::$alertDataArray);
self::$alertDataArray = array();
}
/**
* addAlert - adds a alert to the alert cue
* can be called statically once que has ben created
*
*/
public static function addAlert( $alert)
{
//echo 'adding alert' . $alert;
if ( $alert && $alert != null )
self::$alertDataArray[] = $alert;
}
/**
* viewAlerts - shows whats in the cue
*
*/
public function viewAlerts( )
{
foreach ( self::$alertDataArray as $alert ) {
echo ' alert: ' . $alert;
}
}
/**
* writeAlerts - writes alerts out to log file
*
*/
public function writeAlerts( )
{
//hard coded for the moment
if ( isset (self::$alertDataArray) && is_array(self::$alertDataArray) )
{
$filename = LOG_PATH . "events_" . date('Y-m-d') . ".log";
LoadUtility::safefilerewrite($filename,self::$alertDataArray,"a",true);
return true;
}
return false;
}
}