summaryrefslogtreecommitdiffstats
path: root/frontends/php/tr_status.php
blob: c9479dde717996eb5968eba45183f22e2e1adf93 (plain)
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
<?
	$page["title"] = "Status of triggers";
	$page["file"] = "tr_status.php";

	include "include/config.inc";

	$result=DBselect("select count(*) from triggers t,hosts h,items i,functions f  where t.istrue=1 and f.itemid=i.itemid and h.hostid=i.hostid and t.triggerid=f.triggerid and i.status in (0,2) order by t.triggerid");
	$count=DBget_field($result,0,0);
	setcookie("active_triggers",$count,time()+1800);

//	Number of trigger decreased
	if(isset($active_triggers)&&($count<$active_triggers))
	{
		$audio="warning_on.wav";

	}
//	Number of trigger increased
	if(isset($active_triggers)&&($count>$active_triggers))
	{
		$audio="warning_off.wav";
	}


	$refresh=10;
	if(!isset($onlytrue))
	{
		$refresh=0;
	}
	if(isset($fullscreen))
	{
		show_header($page["title"],$refresh,1);
	}
	else
	{
		show_header($page["title"],$refresh,0);
	}

	if(isset($audio))
	{
		echo "<BGSOUND src=\"audio/$audio\" loop=0>";
	}
?>                                                                                                             

<?
 
	if(!isset($sort))
	{
		$sort='priority';
	}
	if(!isset($onlytrue))
	{
		$onlytrue='false';
	}
	if($noactions!='true')
	{
		$noactions='false';
	}
	if($compact!='true')
	{
		$compact='false';
	}
?>

<?
	if(!isset($select))
	{
		$select="";
	}

	if(!isset($txt_select))
	{
		$txt_select="";
	}

	if(!isset($fullscreen))
	{
		show_table_header_begin();
		echo "STATUS OF TRIGGERS";
	        show_table_v_delimiter();

	        $result=DBselect("select hostid,host from hosts where status in (0,2) order by host");
	        if(isset($hostid))
	        {
	                echo "<A HREF=\"tr_status.php?onlytrue=$onlytrue&noactions=$noactions&compact=$compact&sort=$sort\">all</A>  ";
	        }
	        else
	        {
	                echo "<b>[<A HREF=\"tr_status.php?onlytrue=$onlytrue&noactions=$noactions&compact=$compact&sort=$sort\">all</A>]</b>  ";
	        }
		while($row=DBfetch($result))
	        {
	                if(isset($hostid) && ($row["hostid"] == $hostid))
	                {
	                        echo "<b>[<A HREF=\"tr_status.php?hostid=".$row["hostid"]."&onlytrue=$onlytrue&noactions=$noactions&compact=$compact&sort=$sort\">".$row["host"]."</A>]</b>  ";
	                }
	                else
	                {
	                        echo "<A HREF=\"tr_status.php?hostid=".$row["hostid"]."&onlytrue=$onlytrue&noactions=$noactions&compact=$compact&sort=$sort\">".$row["host"]."</A>  ";
	                }
	        }
	 
		show_table_v_delimiter();
?>

<?
		if(isset($hostid))
		{
			$cond="&hostid=$hostid";
		}
		else
		{
			$cond="";
		}

		if($onlytrue!='true')
		{
			echo "[<A HREF=\"tr_status.php?onlytrue=true&noactions=$noactions&compact=$compact&select=$select&txt_select=$txt_select&sort=$sort$cond\">Show only true</a>] ";
		}
		else
		{
			echo "[<A HREF=\"tr_status.php?noactions=$noactions&compact=$compact&select=$select&txt_select=$txt_select&sort=$sort$cond\">Show all triggers</A>] ";
		}
		if($noactions!='true')
		{
			echo "[<A HREF=\"tr_status.php?onlytrue=$onlytrue&noactions=true&compact=$compact&select=$select&txt_select=$txt_select&sort=$sort$cond\">Hide Actions</A>] ";
		}
		else
		{
			echo "[<A HREF=\"tr_status.php?onlytrue=$onlytrue&noactions=false&compact=$compact&select=$select&txt_select=$txt_select&sort=$sort$cond\">Show Actions</A>] ";
		}
		if($compact!='true')
		{
			echo "[<A HREF=\"tr_status.php?onlytrue=$onlytrue&noactions=$noactions&compact=true&select=$select&txt_select=$txt_select&sort=$sort$cond\">Hide Details</A>] ";
		}
		else
		{
			echo "[<A HREF=\"tr_status.php?onlytrue=$onlytrue&noactions=$noactions&compact=false&select=$select&txt_select=$txt_select&sort=$sort$cond\">Show Details</A>] ";
		}
		
		if($select!='true')
		{
			echo "[<A HREF=\"tr_status.php?onlytrue=$onlytrue&noactions=$noactions&compact=$compact&select=true&txt_select=$txt_select&sort=$sort$cond\">Select</A>] ";
		}
		else
		{
			echo "[<A HREF=\"tr_status.php?onlytrue=$onlytrue&noactions=$noactions&compact=$compact&select=false&sort=$sort$cond\">Hide Select</A>] "; 
			show_table_v_delimiter();
			echo "<form name=\"form1\" method=\"get\" action=\"tr_status.php?select=true\">
  			<input type=\"text\" name=\"txt_select\" value=\"$txt_select\">
  			<input type=\"submit\" name=\"btnSelect\" value=\"Select\">
			<INPUT NAME=\"compact\" TYPE=\"HIDDEN\" value=\"$compact\">
			<INPUT NAME=\"onlytrue\" TYPE=\"HIDDEN\" value=\"$onlytrue\">
			<INPUT NAME=\"noactions\" TYPE=\"HIDDEN\" value=\"$noactions\">			
		        <INPUT NAME=\"select\" TYPE=\"HIDDEN\" value=\"$select\">
			</form>";	
		}
		show_table_header_end();
		echo "<br>";
	}
	
 
 	$time=date("[H:i:s]",time());
  	if(isset($fullscreen))
	{
		show_table_header("<A HREF=\"tr_status.php?onlytrue=$onlytrue&noactions=$noactions&compact=$compact&sort=$sort\">TRIGGERS $time</A>");

		$cond="";
		if(isset($hostid))
		{
			$cond=" and h.hostid=$hostid ";
		}
		if($onlytrue=='true')
		{
			$result=DBselect("select t.priority,count(*) from triggers t,hosts h,items i,functions f  where t.istrue=1 and f.itemid=i.itemid and h.hostid=i.hostid and t.triggerid=f.triggerid and t.description like \"%$txt_select%\" and i.status in (0,2) $cond group by 1");
		}
		else
		{
			$result=DBselect("select t.priority,count(*) from triggers t,hosts h,items i,functions f  where f.itemid=i.itemid and h.hostid=i.hostid and t.triggerid=f.triggerid and t.description like \"%$txt_select%\" and i.status in (0,2) $cond group by 1");
		}
		$p0=$p1=$p2=$p3=$p4=$p5=0;
		for($i=0;$i<DBnum_rows($result);$i++)
		{
			$priority=DBget_field($result,$i,0);
			$count=DBget_field($result,$i,1);
			if($priority==0) $p0=$count;
			if($priority==1) $p1=$count;
			if($priority==2) $p2=$count;
			if($priority==3) $p3=$count;
			if($priority==4) $p4=$count;
			if($priority==5) $p5=$count;
		}
		echo "\n<TABLE BORDER=0 COLS=6 WIDTH=\"100%\" BGCOLOR=\"#CCCCCC\" cellspacing=1 cellpadding=0>";
		echo "<TR ALIGN=CENTER>";
		echo "<TD><B>Not classified: $p0</B></TD>";
		echo "<TD><B>Just information: $p1</B></TD>";
		echo "<TD><B>Warning: $p2</B></TD>";
		echo "<TD BGCOLOR=#DDAAAA><B>Average: $p3</B></TD>";
		echo "<TD BGCOLOR=#FF8888><B>High: $p4</B></TD>";
		echo "<TD BGCOLOR=RED><B>Disaster: $p5</B></TD>";
		echo "</TR>";
		echo "</TABLE>";
	}
	else
	{
		show_table_header("<A HREF=\"tr_status.php?onlytrue=$onlytrue&noactions=$noactions&compact=$compact&fullscreen=1&sort=$sort\">TRIGGERS $time</A>");
	}
  
	echo "<TABLE BORDER=0 COLS=5 WIDTH=\"100%\" BGCOLOR=\"#CCCCCC\" cellspacing=1 cellpadding=3>";

	echo "<TR ALIGN=CENTER>";
	if(isset($fullscreen))
	{
		$fullscreen="&fullscreen=1";
	}
	else
	{
		$fullscreen="";
	}
	if(isset($sort) && $sort=="description")
	{
		echo "<TD ALIGN=LEFT><B>DESCRIPTION";
	}
	else
	{
		echo "<TD ALIGN=LEFT><B><A HREF=\"tr_status.php?sort=description&onlytrue=$onlytrue&noactions=$noactions&compact=$compact&select=$select&txt_select=$txt_select$fullscreen$cond\">Description</a>";
	}
	if($compact!='true') {echo "<BR><FONT SIZE=-1>Expression</FONT></B>";}
	echo "</TD>";

	echo "<TD WIDTH=\"5%\"><B>Status</B></TD>";

	if(!isset($sort)||(isset($sort) && $sort=="priority"))
	{
		echo "<TD WIDTH=\"9%\" ALIGN=CENTER><B>PRIORITY</B></TD>";
	}
	else
	{
		echo "<TD ALIGN=CENTER><B><A HREF=\"tr_status.php?sort=priority&onlytrue=$onlytrue&noactions=$noactions&compact=$compact&select=$select&txt_select=$txt_select$fullscreen$cond\">Priority</a>";
	}
	if($noactions=='true')
		echo "<TD WIDTH=\"12%\" ALIGN=CENTER>";
	else
		echo "<TD WIDTH=\"5%\" ALIGN=CENTER>";

	if(isset($sort) && $sort=="lastchange")
	{
		echo "<B>LAST CHANGE";
	}
	else
	{
		echo "<B><A HREF=\"tr_status.php?sort=lastchange&onlytrue=$onlytrue&noactions=$noactions&compact=$compact&select=$select&txt_select=$txt_select$fullscreen$cond\">Last change</a>";
	}
	echo "</TD>";
   
	if($noactions!='true')
	{  
		echo "<TD WIDTH=\"8%\" NOSAVE><B>Actions</B></TD>";
	}
	echo "<TD WIDTH=\"9%\"><B>Comments</B></TD>";
	echo "</TR>\n";

	if(isset($hostid))
	{
		$cond=" and h.hostid=$hostid ";
	}
	else
	{
		$cond="";
	}

	if(!isset($sort))
	{
		$sort="priority";
	}

	switch ($sort)
	{
		case "description":
			$sort="order by t.description";
			break;
		case "priority":
			$sort="order by t.priority desc, t.description";
			break;
		case "lastchange":
			$sort="order by t.lastchange desc, t.priority";
			break;
		default:
			$sort="order by t.priority desc, t.description";
	}

	if($onlytrue=='true')
	{
		$result=DBselect("select distinct t.triggerid,t.istrue,t.description,t.expression,t.priority,t.lastchange,t.comments,t.url from triggers t,hosts h,items i,functions f  where t.istrue=1 and f.itemid=i.itemid and h.hostid=i.hostid and t.description like \"%$txt_select%\" and t.triggerid=f.triggerid and i.status in (0,2) $cond $sort");
	}
	else
	{
		$result=DBselect("select distinct t.triggerid,t.istrue,t.description,t.expression,t.priority,t.lastchange,t.comments,t.url from triggers t,hosts h,items i,functions f  where f.itemid=i.itemid and h.hostid=i.hostid and t.triggerid=f.triggerid and t.description like \"%$txt_select%\" and i.status in (0,2) $cond $sort");
	}
	$col=0;
	while($row=DBfetch($result))
	{

// Check for dependencies

		$sql="select count(*) from trigger_depends d, triggers t where d.triggerid_down=".$row["triggerid"]." and d.triggerid_up=t.triggerid and t.istrue=1";
		$result2=DBselect($sql);

		if(DBget_field($result2,0,0)>0)
		{
			continue;
		}


		if($col++%2 == 1)	{ echo "<TR BGCOLOR=#EEEEEE>"; }
		else			{ echo "<TR BGCOLOR=#DDDDDD>"; }

		echo "<TD>";

		if($row["url"] == "")
		{
			echo $row["description"];
		}
		else
		{
			echo "<a href='".$row["url"]."'>".$row["description"]."</a>";
		}

		if($compact!='true')
		{
			echo "<BR><FONT COLOR=\"#000000\" SIZE=-2>".explode_exp($row["expression"],1)."</FONT>";
		}
		echo "</TD>";
		if($row["istrue"]==0)
			{ echo "<TD ALIGN=CENTER><FONT COLOR=\"00AA00\">FALSE</FONT></TD>";}
		elseif($row["istrue"]==2)
			{ echo "<TD ALIGN=CENTER><FONT COLOR=\"777777\">DISABLED</FONT></TD>";  }
		else 
			{  echo "<TD ALIGN=CENTER><FONT COLOR=\"AA0000\">TRUE</FONT></TD>"; }

		if($row["priority"]==0)		echo "<TD ALIGN=CENTER>Not classified</TD>";
		elseif($row["priority"]==1)	echo "<TD ALIGN=CENTER>Just information</TD>";
		elseif($row["priority"]==2)	echo "<TD ALIGN=CENTER>Warning</TD>";
		elseif($row["priority"]==3)	echo "<TD ALIGN=CENTER BGCOLOR=#DDAAAA>Average</TD>";
		elseif($row["priority"]==4)	echo "<TD ALIGN=CENTER BGCOLOR=#FF8888>High</TD>";
		elseif($row["priority"]==5)	echo "<TD ALIGN=CENTER BGCOLOR=RED>Disaster !!!</TD>";
		else				echo "<TD ALIGN=CENTER><B>".$row["priority"]."</B></TD>";

		echo "<TD ALIGN=CENTER><A HREF=\"alarms.php?triggerid=".$row["triggerid"]."\">".date("d M H:i:s",$row["lastchange"])."</a>";
		echo "</TD>";

		if($noactions!='true')
		{
			echo "<TD>";
			echo "<A HREF=\"actions.php?triggerid=".$row["triggerid"]."\">Show actions</A> - ";
			echo "<A HREF=\"alarms.php?triggerid=".$row["triggerid"]."\">History</A> - ";
			if(isset($hostid))
			{
				echo "<A HREF=\"triggers.php?hostid=$hostid&triggerid=".$row["triggerid"]."#form\">Change</A>";
			}
			else
			{
				echo "<A HREF=\"triggers.php?triggerid=".$row["triggerid"]."#form\">Change</A>";
			}
			echo "</TD>";
		}
		if($row["comments"] != "")
		{
			echo "<TD ALIGN=CENTER><A HREF=\"tr_comments.php?triggerid=".$row["triggerid"]."\">Show</a></TD>";
		}
		else
		{
			echo "<TD ALIGN=CENTER><A HREF=\"tr_comments.php?triggerid=".$row["triggerid"]."\">Add</a></TD>";
		}
		if($row["istrue"] == 0)	echo "</TR>\n";
	}
	echo "</TABLE>";

	$i=DBnum_rows($result);

	show_table_header("Total:$i");
?>

<?
	show_footer();
?>