summaryrefslogtreecommitdiffstats
path: root/frontends/php/actions.html
blob: 4b8011a94d47592ce7ae3a7c7d30fefe1a9f0cc3 (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
<?
	$page["title"]="Actions";
	$page["file"]="actions.html";

	include "include/config.inc";
	show_header($page["title"],0,0);
?>

<?
	if(isset($register))
	{
		if($register=="add")
		{
			$result=add_action( $triggerid, $userid, $good, $delay, $subject, $message );
			show_messages($result,"Action added","Cannot add action");
		}
		if($register=="update")
		{
			$result=update_action( $actionid, $userid, $good, $delay, $subject, $message );
			show_messages($result,"Action updated","Cannot update action");
			unset($actionid);
		}
		if($register=="delete")
		{
			$result=delete_action($actionid);
			show_messages($result,"Action deleted","Cannot delete action");
			unset($actionid);
		}
	}
?>

<?
	$trigger=select_trigger_by_triggerid($triggerid);
	$expression=explode_exp($trigger["expression"],1);
	$description=$trigger["description"];
	show_table_header("$description<BR>$expression");
?>

<hr>

<?
	$sql="select a.actionid,a.triggerid,u.alias,a.good,a.delay,a.subject,a.message from actions a,users u where a.userid=u.userid and a.triggerid=$triggerid order by u.alias, a.good desc";
	$result=DBselect($sql);

	echo "<CENTER>";
	echo "<TABLE BORDER=0 WIDTH=100% BGCOLOR=\"#CCCCCC\" cellspacing=1 cellpadding=3>";
	echo "<TR>";
	echo "<TD><b>Send message to</b></TD>";
	echo "<TD><b>When trigger</b></TD>";
	echo "<TD><b>Delay</b></TD>";                            
	echo "<TD><b>Subject</b></TD>";
	echo "<TD><b>Message</b></TD>";
	echo "<TD><b>Actions</b></TD>";                               
	echo "</TR>";
	$col=0;
	while($row=DBfetch($result))
	{
		$actid=DBget_field($result,$i,0);
		$good="OFF";
		if(DBget_field($result,$i,3))
		{
			$good="ON";
		}
		$to=DBget_field($result,$i,2);
		$delay=DBget_field($result,$i,4);
		$subject=DBget_field($result,$i,5);
		$msg=DBget_field($result,$i,6);

		if(isset($actionid) && ($actionid==$actid))
		{
			echo "<TR BGCOLOR=#FFDDDD>";
			$col=$col+1;
			$sactid=$actid;
			$sgood=$good;
			$sto=$to;
			$sdelay=$delay;
			$ssubject=$subject;
			$smsg=$msg;
		} 
		else
		{
			if($col==1) 
			{
				echo "<TR BGCOLOR=#EEEEEE>";
				$col=0;
			} else
			{
				echo "<TR BGCOLOR=#DDDDDD>";
				$col=1;
			}
		}
  
		echo "<TD>$to</TD>";
		echo "<TD>$good</TD>";
		echo "<TD>$delay</TD>";
		echo "<TD>$subject</TD>";
		echo "<TD>$msg</TD>";
		echo "<TD>";
		echo " <A HREF=\"actions.html?register=edit&actionid=$actid&triggerid=$triggerid\">Edit</A>";
		echo ", <A HREF=\"actions.html?register=delete&actionid=$actid&triggerid=$triggerid\">Delete</A>";
		echo "</TD></TR>";
	}
	echo "</TABLE>";
?>
</font>
</tr>
</table></center>

<?

	if(isset($actionid))
	{
		$sql="select a.actionid,a.triggerid,a.good,a.delay,a.subject,a.message from actions a where a.actionid=$actionid";
		$result=DBselect($sql);

		$actionid=DBget_field($result,0,0);
		$triggerid=DBget_field($result,0,1);
		$good=DBget_field($result,0,2);
		$delay=DBget_field($result,0,3);
		$subject=DBget_field($result,0,4);
		$message=DBget_field($result,0,5);
	}
	else
	{
		$trigger=select_trigger_by_triggerid($triggerid);
		$description=$trigger["description"];

		$good=1;
		$delay=30;
		$subject=$description;

		$sql="select i.description, h.host, i.key_ from hosts h, items i,functions f where f.triggerid=$triggerid and h.hostid=i.hostid and f.itemid=i.itemid order by i.description";
		$result=DBselect($sql);
		$message="<INSERT YOUR MESSAGE HERE>\n\n------Latest data------\n\n";
		while($row=DBfetch($result))
//		for($i=0;$i<DBnum_rows($result);$i++)
		{
			$message=$message.$row["description"].": \{".$row["host"].":".$row["key_"].".last(0)}  (latest value)\n";
			$message=$message.$row["description"].": \{".$row["host"].":".$row["key_"].".max(300)} (maximum value for last 5 min)\n";
			$message=$message.$row["description"].": \{".$row["host"].":".$row["key_"].".min(300)} (minimum value for last 5 min)\n\n";
		}
		$message=$message."---------End--------\n";
	}
	echo "<br>";
	show_table2_header_begin();
	echo "New action";

	show_table2_v_delimiter();
	echo "<form method=\"post\" action=\"actions.html\">";
	echo "<input name=\"triggerid\" type=\"hidden\" value=$triggerid>";
	if(isset($actionid))
	{
		echo "<input name=\"actionid\" type=\"hidden\" value=$actionid>";
	}
	echo "Send message to";
	show_table2_h_delimiter();
	echo "<SELECT NAME=\"userid\" SIZE=\"1\">";

	$sql="select userid,alias from users order by alias";
	$result=DBselect($sql);
	for($i=0;$i<DBnum_rows($result);$i++)
	{
		$id=DBget_field($result,$i,0);
		$name=DBget_field($result,$i,1);
		if(isset($sto) && ($name==$sto))
		{
			echo "<option value=\"$id\" SELECTED>$name";
		}
		else
		{
			echo "<option value=\"$id\">$name";
		}
	}
	echo "</select>";

	show_table2_v_delimiter();
	echo "When trigger becomes";
	show_table2_h_delimiter();
	echo "<select name=\"good\" size=1>";
	echo "<OPTION VALUE=\"1\""; if($good==1) echo "SELECTED"; echo ">ON";
	echo "<OPTION VALUE=\"0\""; if($good==0) echo "SELECTED"; echo ">OFF";
	echo "</SELECT>";

	show_table2_v_delimiter();
	echo "Delay";
	show_table2_h_delimiter();
	echo "<input name=\"delay\" value=\"$delay\" size=5>";

	show_table2_v_delimiter();
	echo "Subject";
	show_table2_h_delimiter();
	echo "<input name=\"subject\" value=\"$subject\" size=70>";

	show_table2_v_delimiter();
	echo "Message";
	show_table2_h_delimiter();
 	echo "<textarea name=\"message\" cols=70 ROWS=\"7\" wrap=\"soft\">$message</TEXTAREA>";

	show_table2_v_delimiter2();
	echo "<input type=\"submit\" name=\"register\" value=\"add\">";
	if(isset($actionid))
	{
		echo "<input type=\"submit\" name=\"register\" value=\"update\">";
	}

	show_table2_header_end();

	show_footer();
?>