1<?php 2 3// Pandora FMS - http://pandorafms.com 4// ================================================== 5// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas 6// Please see http://pandorafms.org for full contribution list 7 8// This program is free software; you can redistribute it and/or 9// modify it under the terms of the GNU General Public License 10// as published by the Free Software Foundation for version 2. 11// This program is distributed in the hope that it will be useful, 12// but WITHOUT ANY WARRANTY; without even the implied warranty of 13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14// GNU General Public License for more details. 15 16 17// Load global vars 18 19if (! check_acl ($config['id_user'], 0, "LW")) { 20 db_pandora_audit("ACL Violation", 21 "Trying to access SNMP Alert Management"); 22 require ("general/noaccess.php"); 23 return; 24} 25 26$trap_types = array( 27 SNMP_TRAP_TYPE_NONE => __('None'), 28 SNMP_TRAP_TYPE_COLD_START => __('Cold start (0)'), 29 SNMP_TRAP_TYPE_WARM_START => __('Warm start (1)'), 30 SNMP_TRAP_TYPE_LINK_DOWN => __('Link down (2)'), 31 SNMP_TRAP_TYPE_LINK_UP => __('Link up (3)'), 32 SNMP_TRAP_TYPE_AUTHENTICATION_FAILURE => __('Authentication failure (4)'), 33 SNMP_TRAP_TYPE_OTHER => __('Other')); 34 35// Form submitted 36// ============= 37 38$update_alert = (bool)get_parameter('update_alert', false); 39$create_alert = (bool)get_parameter('create_alert', false); 40$save_alert = (bool)get_parameter('save_alert', false); 41$modify_alert = (bool)get_parameter('modify_alert', false); 42$delete_alert = (bool)get_parameter('delete_alert', false); 43$multiple_delete = (bool)get_parameter('multiple_delete', false); 44$add_action = (bool)get_parameter('add_alert', 0); 45$delete_action = get_parameter('delete_action', 0); 46 47if ($add_action) { 48 $values['id_alert_snmp'] = (int) get_parameter('id_alert_snmp'); 49 $values['alert_type'] = (int) get_parameter('alert_type'); 50 $values[db_escape_key_identifier('al_field1')] = get_parameter('field1_value'); 51 $values[db_escape_key_identifier('al_field2')] = get_parameter('field2_value'); 52 $values[db_escape_key_identifier('al_field3')] = get_parameter('field3_value'); 53 $values[db_escape_key_identifier('al_field4')] = get_parameter('field4_value'); 54 $values[db_escape_key_identifier('al_field5')] = get_parameter('field5_value'); 55 $values[db_escape_key_identifier('al_field6')] = get_parameter('field6_value'); 56 $values[db_escape_key_identifier('al_field7')] = get_parameter('field7_value'); 57 $values[db_escape_key_identifier('al_field8')] = get_parameter('field8_value'); 58 $values[db_escape_key_identifier('al_field9')] = get_parameter('field9_value'); 59 $values[db_escape_key_identifier('al_field10')] = get_parameter('field10_value'); 60 61 $result = db_process_sql_insert('talert_snmp_action', $values); 62} 63 64if ($delete_action) { 65 66 $action_id = get_parameter('action_id'); 67 68 $result = db_process_sql_delete('talert_snmp_action', array('id'=>$action_id)); 69} 70 71if ($update_alert || $modify_alert) { 72 ui_print_page_header(__('SNMP Console')." » ".__('Update alert'), 73 "images/op_snmp.png", false, "snmp_alert", false); 74} 75else if ($create_alert || $save_alert) { 76 ui_print_page_header(__('SNMP Console')." » ".__('Create alert'), 77 "images/op_snmp.png", false, "snmp_alert", false); 78} 79else { 80 ui_print_page_header(__('SNMP Console')." » ".__('Alert overview'), 81 "images/op_snmp.png", false, "snmp_alert", false); 82} 83 84if ($save_alert || $modify_alert) { 85 $id_as = (int) get_parameter("id_alert_snmp", -1); 86 87 $source_ip = (string) get_parameter_post ("source_ip"); 88 $alert_type = (int) get_parameter_post ("alert_type"); //Event, e-mail 89 $description = (string) get_parameter_post ("description"); 90 $oid = (string) get_parameter_post ("oid"); 91 $custom_value = (string) get_parameter_post ("custom_value"); 92 $time_threshold = (int) get_parameter_post ("time_threshold", SECONDS_5MINUTES); 93 $time_other = (int) get_parameter_post ("time_other", -1); 94 $al_field1 = (string) get_parameter_post ("field1_value"); 95 $al_field2 = (string) get_parameter_post ("field2_value"); 96 $al_field3 = (string) get_parameter_post ("field3_value"); 97 $al_field4 = (string) get_parameter_post ("field4_value"); 98 $al_field5 = (string) get_parameter_post ("field5_value"); 99 $al_field6 = (string) get_parameter_post ("field6_value"); 100 $al_field7 = (string) get_parameter_post ("field7_value"); 101 $al_field8 = (string) get_parameter_post ("field8_value"); 102 $al_field9 = (string) get_parameter_post ("field9_value"); 103 $al_field10 = (string) get_parameter_post ("al_field10"); 104 $max_alerts = (int) get_parameter_post ("max_alerts", 1); 105 $min_alerts = (int) get_parameter_post ("min_alerts", 0); 106 $priority = (int) get_parameter_post ("priority", 0); 107 $custom_oid_data_1 = (string) get_parameter ("custom_oid_data_1"); 108 $custom_oid_data_2 = (string) get_parameter ("custom_oid_data_2"); 109 $custom_oid_data_3 = (string) get_parameter ("custom_oid_data_3"); 110 $custom_oid_data_4 = (string) get_parameter ("custom_oid_data_4"); 111 $custom_oid_data_5 = (string) get_parameter ("custom_oid_data_5"); 112 $custom_oid_data_6 = (string) get_parameter ("custom_oid_data_6"); 113 $custom_oid_data_7 = (string) get_parameter ("custom_oid_data_7"); 114 $custom_oid_data_8 = (string) get_parameter ("custom_oid_data_8"); 115 $custom_oid_data_9 = (string) get_parameter ("custom_oid_data_9"); 116 $custom_oid_data_10 = (string) get_parameter ("custom_oid_data_10"); 117 $custom_oid_data_11 = (string) get_parameter ("custom_oid_data_11"); 118 $custom_oid_data_12 = (string) get_parameter ("custom_oid_data_12"); 119 $custom_oid_data_13 = (string) get_parameter ("custom_oid_data_13"); 120 $custom_oid_data_14 = (string) get_parameter ("custom_oid_data_14"); 121 $custom_oid_data_15 = (string) get_parameter ("custom_oid_data_15"); 122 $custom_oid_data_16 = (string) get_parameter ("custom_oid_data_16"); 123 $custom_oid_data_17 = (string) get_parameter ("custom_oid_data_17"); 124 $custom_oid_data_18 = (string) get_parameter ("custom_oid_data_18"); 125 $custom_oid_data_19 = (string) get_parameter ("custom_oid_data_19"); 126 $custom_oid_data_20 = (string) get_parameter ("custom_oid_data_20"); 127 $order_1 = (int) get_parameter ("order_1", 1); 128 $order_2 = (int) get_parameter ("order_2", 2); 129 $order_3 = (int) get_parameter ("order_3", 3); 130 $order_4 = (int) get_parameter ("order_4", 4); 131 $order_5 = (int) get_parameter ("order_5", 5); 132 $order_6 = (int) get_parameter ("order_6", 6); 133 $order_7 = (int) get_parameter ("order_7", 7); 134 $order_8 = (int) get_parameter ("order_8", 8); 135 $order_9 = (int) get_parameter ("order_9", 9); 136 $order_10 = (int) get_parameter ("order_10", 10); 137 $order_11 = (int) get_parameter ("order_11", 11); 138 $order_12 = (int) get_parameter ("order_12", 12); 139 $order_13 = (int) get_parameter ("order_13", 13); 140 $order_14 = (int) get_parameter ("order_14", 14); 141 $order_15 = (int) get_parameter ("order_15", 15); 142 $order_16 = (int) get_parameter ("order_16", 16); 143 $order_17 = (int) get_parameter ("order_17", 17); 144 $order_18 = (int) get_parameter ("order_18", 18); 145 $order_19 = (int) get_parameter ("order_19", 19); 146 $order_20 = (int) get_parameter ("order_20", 20); 147 148 $trap_type = (int) get_parameter ("trap_type", -1); 149 $single_value = (string) get_parameter ("single_value"); 150 $position = (int) get_parameter ("position"); 151 $group = (int) get_parameter ("group"); 152 153 if ($time_threshold == -1) { 154 $time_threshold = $time_other; 155 } 156 157 if ($save_alert) { 158 $values = array( 159 'id_alert' => $alert_type, 160 'al_field1' => $al_field1, 161 'al_field2' => $al_field2, 162 'al_field3' => $al_field3, 163 'al_field4' => $al_field4, 164 'al_field5' => $al_field5, 165 'al_field6' => $al_field6, 166 'al_field7' => $al_field7, 167 'al_field8' => $al_field8, 168 'al_field9' => $al_field9, 169 'al_field10' => $al_field10, 170 'description' => $description, 171 'agent' => $source_ip, 172 'custom_oid' => $custom_value, 173 'oid' => $oid, 174 'time_threshold' => $time_threshold, 175 'max_alerts' => $max_alerts, 176 'min_alerts' => $min_alerts, 177 'priority' => $priority, 178 db_escape_key_identifier('_snmp_f1_') => $custom_oid_data_1, 179 db_escape_key_identifier('_snmp_f2_') => $custom_oid_data_2, 180 db_escape_key_identifier('_snmp_f3_') => $custom_oid_data_3, 181 db_escape_key_identifier('_snmp_f4_') => $custom_oid_data_4, 182 db_escape_key_identifier('_snmp_f5_') => $custom_oid_data_5, 183 db_escape_key_identifier('_snmp_f6_') => $custom_oid_data_6, 184 db_escape_key_identifier('_snmp_f7_') => $custom_oid_data_7, 185 db_escape_key_identifier('_snmp_f8_') => $custom_oid_data_8, 186 db_escape_key_identifier('_snmp_f9_') => $custom_oid_data_9, 187 db_escape_key_identifier('_snmp_f10_') => $custom_oid_data_10, 188 db_escape_key_identifier('_snmp_f11_') => $custom_oid_data_11, 189 db_escape_key_identifier('_snmp_f12_') => $custom_oid_data_12, 190 db_escape_key_identifier('_snmp_f13_') => $custom_oid_data_13, 191 db_escape_key_identifier('_snmp_f14_') => $custom_oid_data_14, 192 db_escape_key_identifier('_snmp_f15_') => $custom_oid_data_15, 193 db_escape_key_identifier('_snmp_f16_') => $custom_oid_data_16, 194 db_escape_key_identifier('_snmp_f17_') => $custom_oid_data_17, 195 db_escape_key_identifier('_snmp_f18_') => $custom_oid_data_18, 196 db_escape_key_identifier('_snmp_f19_') => $custom_oid_data_19, 197 db_escape_key_identifier('_snmp_f20_') => $custom_oid_data_20, 198 'order_1' => $order_1, 199 'order_2' => $order_2, 200 'order_3' => $order_3, 201 'order_4' => $order_4, 202 'order_5' => $order_5, 203 'order_6' => $order_6, 204 'order_7' => $order_7, 205 'order_8' => $order_8, 206 'order_9' => $order_9, 207 'order_10' => $order_10, 208 'order_11' => $order_11, 209 'order_12' => $order_12, 210 'order_13' => $order_13, 211 'order_14' => $order_14, 212 'order_15' => $order_15, 213 'order_16' => $order_16, 214 'order_17' => $order_17, 215 'order_18' => $order_18, 216 'order_19' => $order_19, 217 'order_20' => $order_20, 218 'trap_type' => $trap_type, 219 'single_value' => $single_value, 220 'position' => $position, 221 'id_group' => $group); 222 223 $result = db_process_sql_insert('talert_snmp', $values); 224 225 if (!$result) { 226 db_pandora_audit("SNMP management", "Fail try to create snmp alert"); 227 ui_print_error_message(__('There was a problem creating the alert')); 228 } 229 else { 230 db_pandora_audit("SNMP management", "Create snmp alert #$result"); 231 ui_print_success_message(__('Successfully created')); 232 } 233 234 } 235 else { 236 $sql = sprintf ("UPDATE talert_snmp SET 237 priority = %d, id_alert = %d, al_field1 = '%s', 238 al_field2 = '%s', al_field3 = '%s', al_field4 = '%s', 239 al_field5 = '%s', al_field6 = '%s',al_field7 = '%s', 240 al_field8 = '%s', al_field9 = '%s',al_field10 = '%s', 241 description = '%s', 242 agent = '%s', custom_oid = '%s', oid = '%s', 243 time_threshold = %d, max_alerts = %d, min_alerts = %d, 244 ".db_escape_key_identifier('_snmp_f1_') ."= '%s', 245 ".db_escape_key_identifier('_snmp_f2_') ."= '%s', 246 ".db_escape_key_identifier('_snmp_f3_') ."= '%s', 247 ".db_escape_key_identifier('_snmp_f4_') ."= '%s', 248 ".db_escape_key_identifier('_snmp_f5_') ."= '%s', 249 ".db_escape_key_identifier('_snmp_f6_') ."= '%s', 250 ".db_escape_key_identifier('_snmp_f7_') ."= '%s', 251 ".db_escape_key_identifier('_snmp_f8_') ."= '%s', 252 ".db_escape_key_identifier('_snmp_f9_') ."= '%s', 253 ".db_escape_key_identifier('_snmp_f10_')." = '%s', 254 ".db_escape_key_identifier('_snmp_f11_')." = '%s', 255 ".db_escape_key_identifier('_snmp_f12_')." = '%s', 256 ".db_escape_key_identifier('_snmp_f13_')." = '%s', 257 ".db_escape_key_identifier('_snmp_f14_')." = '%s', 258 ".db_escape_key_identifier('_snmp_f15_')." = '%s', 259 ".db_escape_key_identifier('_snmp_f16_')." = '%s', 260 ".db_escape_key_identifier('_snmp_f17_')." = '%s', 261 ".db_escape_key_identifier('_snmp_f18_')." = '%s', 262 ".db_escape_key_identifier('_snmp_f19_')." = '%s', 263 ".db_escape_key_identifier('_snmp_f20_')." = '%s', 264 order_1 = '%d', 265 order_2 = '%d', order_3 = '%d', order_4 = '%d', 266 order_5 = '%d', order_6 = '%d', order_7 = '%d', 267 order_8 = '%d', order_9 = '%d', order_10 = '%d', 268 order_11 = '%d', order_12 = '%d', order_13 = '%d', 269 order_14 = '%d', order_15 = '%d', order_16 = '%d', 270 order_17 = '%d', order_18 = '%d', order_19 = '%d', 271 order_20 = '%d', trap_type = %d, 272 single_value = '%s', position = '%s', id_group ='%s' 273 WHERE id_as = %d", 274 $priority, $alert_type, $al_field1, $al_field2, $al_field3, 275 $al_field4, $al_field5, $al_field6, $al_field7, $al_field8, 276 $al_field9, $al_field10, 277 $description, $source_ip, $custom_value, $oid, $time_threshold, 278 $max_alerts, $min_alerts, $custom_oid_data_1, $custom_oid_data_2, 279 $custom_oid_data_3, $custom_oid_data_4, $custom_oid_data_5, 280 $custom_oid_data_6, $custom_oid_data_7, $custom_oid_data_8, 281 $custom_oid_data_9, $custom_oid_data_10, $custom_oid_data_11, 282 $custom_oid_data_12, $custom_oid_data_13, $custom_oid_data_14, 283 $custom_oid_data_15, $custom_oid_data_16, $custom_oid_data_17, 284 $custom_oid_data_18, $custom_oid_data_19, $custom_oid_data_20, 285 $order_1, $order_2, $order_3, $order_4, $order_5, 286 $order_6, $order_7, $order_8, $order_9, $order_10, 287 $order_11, $order_12, $order_13, $order_14, $order_15, 288 $order_16, $order_17, $order_18, $order_19, $order_20, 289 $trap_type, $single_value, $position, $group, $id_as); 290 291 $result = db_process_sql ($sql); 292 293 if (!$result) { 294 db_pandora_audit("SNMP management", "Fail try to update snmp alert #$id_as"); 295 ui_print_error_message(__('There was a problem updating the alert')); 296 } 297 else { 298 db_pandora_audit("SNMP management", "Update snmp alert #$id_as"); 299 ui_print_success_message(__('Successfully updated')); 300 } 301 } 302} 303 304// From variable init 305// ================== 306if ($update_alert) { 307 $id_as = (int) get_parameter("id_alert_snmp", -1); 308 309 $alert = db_get_row ("talert_snmp", "id_as", $id_as); 310 $id_as = $alert["id_as"]; 311 $source_ip = $alert["agent"]; 312 $alert_type = $alert["id_alert"]; 313 $description = $alert["description"]; 314 $oid = $alert["oid"]; 315 $custom_value = $alert["custom_oid"]; 316 $time_threshold = $alert["time_threshold"]; 317 $al_field1 = $alert["al_field1"]; 318 $al_field2 = $alert["al_field2"]; 319 $al_field3 = $alert["al_field3"]; 320 $al_field4 = $alert["al_field4"]; 321 $al_field5 = $alert["al_field5"]; 322 $al_field6 = $alert["al_field6"]; 323 $al_field7 = $alert["al_field7"]; 324 $al_field8 = $alert["al_field8"]; 325 $al_field9 = $alert["al_field9"]; 326 $al_field10 = $alert["al_field10"]; 327 $max_alerts = $alert["max_alerts"]; 328 $min_alerts = $alert["min_alerts"]; 329 $priority = $alert["priority"]; 330 $custom_oid_data_1 = $alert["_snmp_f1_"]; 331 $custom_oid_data_2 = $alert["_snmp_f2_"]; 332 $custom_oid_data_3 = $alert["_snmp_f3_"]; 333 $custom_oid_data_4 = $alert["_snmp_f4_"]; 334 $custom_oid_data_5 = $alert["_snmp_f5_"]; 335 $custom_oid_data_6 = $alert["_snmp_f6_"]; 336 $custom_oid_data_7 = $alert["_snmp_f7_"]; 337 $custom_oid_data_8 = $alert["_snmp_f8_"]; 338 $custom_oid_data_9 = $alert["_snmp_f9_"]; 339 $custom_oid_data_10 = $alert["_snmp_f10_"]; 340 $custom_oid_data_11 = $alert["_snmp_f11_"]; 341 $custom_oid_data_12 = $alert["_snmp_f12_"]; 342 $custom_oid_data_13 = $alert["_snmp_f13_"]; 343 $custom_oid_data_14 = $alert["_snmp_f14_"]; 344 $custom_oid_data_15 = $alert["_snmp_f15_"]; 345 $custom_oid_data_16 = $alert["_snmp_f16_"]; 346 $custom_oid_data_17 = $alert["_snmp_f17_"]; 347 $custom_oid_data_18 = $alert["_snmp_f18_"]; 348 $custom_oid_data_19 = $alert["_snmp_f19_"]; 349 $custom_oid_data_20 = $alert["_snmp_f20_"]; 350 $order_1 = $alert["order_1"]; 351 $order_2 = $alert["order_2"]; 352 $order_3 = $alert["order_3"]; 353 $order_4 = $alert["order_4"]; 354 $order_5 = $alert["order_5"]; 355 $order_6 = $alert["order_6"]; 356 $order_7 = $alert["order_7"]; 357 $order_8 = $alert["order_8"]; 358 $order_9 = $alert["order_9"]; 359 $order_10 = $alert["order_10"]; 360 $order_11 = $alert["order_11"]; 361 $order_12 = $alert["order_12"]; 362 $order_13 = $alert["order_13"]; 363 $order_14 = $alert["order_14"]; 364 $order_15 = $alert["order_15"]; 365 $order_16 = $alert["order_16"]; 366 $order_17 = $alert["order_17"]; 367 $order_18 = $alert["order_18"]; 368 $order_19 = $alert["order_19"]; 369 $order_20 = $alert["order_20"]; 370 $trap_type = $alert["trap_type"]; 371 $single_value = $alert["single_value"]; 372 $position = $alert["position"]; 373 $group = $alert["id_group"]; 374} 375elseif ($create_alert) { 376 // Variable init 377 $id_as = -1; 378 $source_ip = ""; 379 $alert_type = 1; //Event, e-mail 380 $description = ""; 381 $oid = ""; 382 $custom_value = ""; 383 $time_threshold = SECONDS_5MINUTES; 384 $al_field1 = ""; 385 $al_field2 = ""; 386 $al_field3 = ""; 387 $al_field4 = ""; 388 $al_field5 = ""; 389 $al_field6 = ""; 390 $al_field7 = ""; 391 $al_field8 = ""; 392 $al_field9 = ""; 393 $al_field10 = ""; 394 $max_alerts = 1; 395 $min_alerts = 0; 396 $priority = 0; 397 $custom_oid_data_1 = ''; 398 $custom_oid_data_2 = ''; 399 $custom_oid_data_3 = ''; 400 $custom_oid_data_4 = ''; 401 $custom_oid_data_5 = ''; 402 $custom_oid_data_6 = ''; 403 $custom_oid_data_7 = ''; 404 $custom_oid_data_8 = ''; 405 $custom_oid_data_9 = ''; 406 $custom_oid_data_10 = ''; 407 $custom_oid_data_11 = ''; 408 $custom_oid_data_12 = ''; 409 $custom_oid_data_13 = ''; 410 $custom_oid_data_14 = ''; 411 $custom_oid_data_15 = ''; 412 $custom_oid_data_16 = ''; 413 $custom_oid_data_17 = ''; 414 $custom_oid_data_18 = ''; 415 $custom_oid_data_19 = ''; 416 $custom_oid_data_20 = ''; 417 $order_1 = 1; 418 $order_2 = 2; 419 $order_3 = 3; 420 $order_4 = 4; 421 $order_5 = 5; 422 $order_6 = 6; 423 $order_7 = 7; 424 $order_8 = 8; 425 $order_9 = 9; 426 $order_10 = 10; 427 $order_11 = 11; 428 $order_12 = 12; 429 $order_13 = 13; 430 $order_14 = 14; 431 $order_15 = 15; 432 $order_16 = 16; 433 $order_17 = 17; 434 $order_18 = 18; 435 $order_19 = 19; 436 $order_20 = 20; 437 $trap_type = -1; 438 $single_value = ''; 439 $position = 0; 440 $group = 0; 441} 442 443// Header 444 445// Alert Delete 446// ============= 447if ($delete_alert) { // Delete alert 448 $alert_delete = (int) get_parameter_get ("delete_alert", 0); 449 450 $result = db_process_sql_delete('talert_snmp', 451 array('id_as' => $alert_delete)); 452 453 if ($result === false) { 454 db_pandora_audit("SNMP management", "Fail try to delete snmp alert #$alert_delete"); 455 ui_print_error_message(__('There was a problem deleting the alert')); 456 } 457 else { 458 db_pandora_audit("SNMP management", "Delete snmp alert #$alert_delete"); 459 ui_print_success_message(__('Successfully deleted')); 460 } 461} 462 463if ($multiple_delete) { 464 $delete_ids = get_parameter('delete_ids', array()); 465 466 $total = count($delete_ids); 467 468 $count = 0; 469 foreach ($delete_ids as $alert_delete) { 470 $result = db_process_sql_delete('talert_snmp', 471 array('id_as' => $alert_delete)); 472 473 if ($result !== false) { 474 db_pandora_audit("SNMP management", "Delete snmp alert #$alert_delete"); 475 $count++; 476 } 477 else { 478 db_pandora_audit("SNMP management", "Fail try to delete snmp alert #$alert_delete"); 479 } 480 } 481 482 if ($count == $total) { 483 ui_print_success_message( 484 __('Successfully deleted alerts (%s / %s)', $count, $total)); 485 } 486 else { 487 ui_print_error_message( 488 __('Unsuccessfully deleted alerts (%s / %s)', $count, $total)); 489 } 490} 491 492$user_groups = users_get_groups($config['id_user'],"AR", true); 493$str_user_groups = ''; 494$i = 0; 495foreach ($user_groups as $id => $name) { 496 if ($i == 0) { 497 $str_user_groups .= $id; 498 } 499 else { 500 $str_user_groups .= ','.$id; 501 } 502 $i++; 503} 504 505// Alert form 506if ($create_alert || $update_alert) { 507//if (isset ($_GET["update_alert"])) { 508 //the update_alert means the form should be displayed. If update_alert > 1 then an existing alert is updated 509 echo '<form name="agente" method="post" action="index.php?sec=snmpconsole&sec2=godmode/snmpconsole/snmp_alert">'; 510 511 html_print_input_hidden('id_alert_snmp', $id_as); 512 513 if ($create_alert) { 514 html_print_input_hidden('save_alert', 1); 515 } 516 if ($update_alert) { 517 html_print_input_hidden('modify_alert', 1); 518 } 519 520 /* SNMP alert filters */ 521 522 echo '<table cellpadding="0" cellspacing="0" width="100%" class="databox filter" style="font-weight: bold">'; 523 524 // Description 525 echo '<tr>' . 526 '<td class="datos" valign="top">' . __('Description') . '</td>' . 527 '<td class="datos">'; 528 html_print_textarea('description', 3, 2, $description, 'style="width:400px;"'); 529 echo '</td>' . 530 '</tr>'; 531 532 //echo '<tr><td class="datos"><b>' . __('Alert filters') . ui_print_help_icon("snmp_alert_filters", true) . '</b></td></tr>'; 533 534 // OID 535 echo '<tr id="tr-oid">' . 536 '<td class="datos2">' . __('Enterprise String') . '</td>' . 537 '<td class="datos2">'; 538 html_print_input_text ("oid", $oid, '', 50, 255); 539 echo '</td></tr>'; 540 541 // Custom 542 echo '<tr id="tr-custom_value"><td class="datos" valign="top">'.__('Custom Value/OID'); 543 echo ui_print_help_icon ("snmp_alert_custom", true); 544 545 echo '</td><td class="datos">'; 546 html_print_textarea ("custom_value", $custom_value, 2, $custom_value, 'style="width:400px;"'); 547 548 echo '</td></tr>'; 549 550 // SNMP Agent 551 echo '<tr id="tr-source_ip"><td class="datos2">'.__('SNMP Agent').' (IP)</td><td class="datos2">'; 552 html_print_input_text ("source_ip", $source_ip, '', 20); 553 echo '</td></tr>'; 554 555 // Group 556 echo '<tr id="tr-group"><td class="datos2">'.__('Group').'</td><td class="datos2">'; 557 html_print_select_groups($config['id_user'], "AR", true, "group", 558 $group, '', '', 0, false, false, false, '', false, false, 559 false, false, 'id_grupo', false); 560 echo '</td></tr>'; 561 562 // Trap type 563 echo '<tr><td class="datos">'.__('Trap type').'</td><td class="datos">'; 564 echo html_print_select ($trap_types, 'trap_type', $trap_type, '', '', '', false, false, false); 565 echo '</td></tr>'; 566 567 // Single value 568 echo '<tr><td class="datos">'.__('Single value').'</td><td class="datos">'; 569 html_print_input_text ("single_value", $single_value, '', 20); 570 echo '</td></tr>'; 571 572 // Variable bindings/Data #1 573 echo '<tr id="tr-custom_value">' . 574 '<td class="datos" valign="top">' . 575 __('Variable bindings/Data') . 576 ui_print_help_icon ("field_match_snmp", true) . 577 '</td>' . 578 '<td class="datos">'; 579 echo '#'; 580 html_print_input_text ("order_1", $order_1, '', 4); 581 html_print_input_text ("custom_oid_data_1", $custom_oid_data_1, '', 60); 582 echo '</td></tr>'; 583 584 // Variable bindings/Data #2 585 echo '<tr id="tr-custom_value"><td class="datos" valign="top">'.__('Variable bindings/Data'); 586 //echo ui_print_help_icon ("snmp_alert_custom", true); 587 588 echo '</td><td class="datos">'; 589 echo '#'; 590 html_print_input_text ("order_2", $order_2, '', 4); 591 html_print_input_text ("custom_oid_data_2", $custom_oid_data_2, '', 60); 592 echo '</td></tr>'; 593 594 // Variable bindings/Data #3 595 echo '<tr id="tr-custom_value"><td class="datos" valign="top">'.__('Variable bindings/Data'); 596 //echo ui_print_help_icon ("snmp_alert_custom", true); 597 598 echo '</td><td class="datos">'; 599 echo '#'; 600 html_print_input_text ("order_3", $order_3, '', 4); 601 html_print_input_text ("custom_oid_data_3", $custom_oid_data_3, '', 60); 602 echo '</td></tr>'; 603 604 // Variable bindings/Data #4 605 echo '<tr id="tr-custom_value">' . 606 '<td class="datos" valign="top">' . 607 __('Variable bindings/Data'); 608 //echo ui_print_help_icon ("snmp_alert_custom", true); 609 610 echo '</td><td class="datos">'; 611 echo '#'; 612 html_print_input_text ("order_4", $order_4, '', 4); 613 html_print_input_text ("custom_oid_data_4", $custom_oid_data_4, '', 60); 614 echo '</td></tr>'; 615 616 // Variable bindings/Data #5 617 echo '<tr id="tr-custom_value">' . 618 '<td class="datos" valign="top">' . 619 __('Variable bindings/Data'); 620 //echo ui_print_help_icon ("snmp_alert_custom", true); 621 622 echo '</td><td class="datos">'; 623 echo '#'; 624 html_print_input_text ("order_5", $order_5, '', 4); 625 html_print_input_text ("custom_oid_data_5", $custom_oid_data_5, '', 60); 626 echo '</td></tr>'; 627 628 // Variable bindings/Data #6 629 echo '<tr id="tr-custom_value">' . 630 '<td class="datos" valign="top">' . 631 __('Variable bindings/Data'); 632 //echo ui_print_help_icon ("snmp_alert_custom", true); 633 634 echo '</td><td class="datos">'; 635 echo '#'; 636 html_print_input_text ("order_6", $order_6, '', 4); 637 html_print_input_text ("custom_oid_data_6", $custom_oid_data_6, '', 60); 638 echo '</td></tr>'; 639 640 // Variable bindings/Data #7 641 echo '<tr id="tr-custom_value">' . 642 '<td class="datos" valign="top">' . 643 __('Variable bindings/Data'); 644 echo '</td><td class="datos">'; 645 echo '#'; 646 html_print_input_text ("order_7", $order_7, '', 4); 647 html_print_input_text ("custom_oid_data_7", $custom_oid_data_7, '', 60); 648 echo '</td></tr>'; 649 650 // Variable bindings/Data #8 651 echo '<tr id="tr-custom_value">' . 652 '<td class="datos" valign="top">' . 653 __('Variable bindings/Data'); 654 echo '</td><td class="datos">'; 655 echo '#'; 656 html_print_input_text ("order_8", $order_8, '', 4); 657 html_print_input_text ("custom_oid_data_8", $custom_oid_data_8, '', 60); 658 echo '</td></tr>'; 659 660 // Variable bindings/Data #9 661 echo '<tr id="tr-custom_value">' . 662 '<td class="datos" valign="top">' . 663 __('Variable bindings/Data'); 664 echo '</td><td class="datos">'; 665 echo '#'; 666 html_print_input_text ("order_9", $order_9, '', 4); 667 html_print_input_text ("custom_oid_data_9", $custom_oid_data_9, '', 60); 668 echo '</td></tr>'; 669 670 // Variable bindings/Data #10 671 echo '<tr id="tr-custom_value">' . 672 '<td class="datos" valign="top">' . 673 __('Variable bindings/Data'); 674 echo '</td><td class="datos">'; 675 echo '#'; 676 html_print_input_text ("order_10", $order_10, '', 4); 677 html_print_input_text ("custom_oid_data_10", $custom_oid_data_10, '', 60); 678 echo '</td></tr>'; 679 680 // Variable bindings/Data #11 681 echo '<tr id="tr-custom_value">' . 682 '<td class="datos" valign="top">' . 683 __('Variable bindings/Data'); 684 echo '</td><td class="datos">'; 685 echo '#'; 686 html_print_input_text ("order_11", $order_11, '', 4); 687 html_print_input_text ("custom_oid_data_11", $custom_oid_data_11, '', 60); 688 echo '</td></tr>'; 689 690 // Variable bindings/Data #12 691 echo '<tr id="tr-custom_value">' . 692 '<td class="datos" valign="top">' . __('Variable bindings/Data'); 693 echo '</td><td class="datos">'; 694 echo '#'; 695 html_print_input_text ("order_12", $order_12, '', 4); 696 html_print_input_text ("custom_oid_data_12", $custom_oid_data_12, '', 60); 697 echo '</td></tr>'; 698 699 // Variable bindings/Data #13 700 echo '<tr id="tr-custom_value"><td class="datos" valign="top">' . 701 __('Variable bindings/Data'); 702 echo '</td><td class="datos">'; 703 echo '#'; 704 html_print_input_text ("order_13", $order_13, '', 4); 705 html_print_input_text ("custom_oid_data_13", $custom_oid_data_13, '', 60); 706 echo '</td></tr>'; 707 708 // Variable bindings/Data #14 709 echo '<tr id="tr-custom_value"><td class="datos" valign="top">' . 710 __('Variable bindings/Data'); 711 echo '</td><td class="datos">'; 712 echo '#'; 713 html_print_input_text ("order_14", $order_14, '', 4); 714 html_print_input_text ("custom_oid_data_14", $custom_oid_data_14, '', 60); 715 echo '</td></tr>'; 716 717 // Variable bindings/Data #15 718 echo '<tr id="tr-custom_value"><td class="datos" valign="top">' . 719 __('Variable bindings/Data'); 720 echo '</td><td class="datos">'; 721 echo '#'; 722 html_print_input_text ("order_15", $order_15, '', 4); 723 html_print_input_text ("custom_oid_data_15", $custom_oid_data_15, '', 60); 724 echo '</td></tr>'; 725 726 // Variable bindings/Data #16 727 echo '<tr id="tr-custom_value"><td class="datos" valign="top">' . 728 __('Variable bindings/Data'); 729 echo '</td><td class="datos">'; 730 echo '#'; 731 html_print_input_text ("order_16", $order_16, '', 4); 732 html_print_input_text ("custom_oid_data_16", $custom_oid_data_16, '', 60); 733 echo '</td></tr>'; 734 735 // Variable bindings/Data #17 736 echo '<tr id="tr-custom_value"><td class="datos" valign="top">' . 737 __('Variable bindings/Data'); 738 echo '</td><td class="datos">'; 739 echo '#'; 740 html_print_input_text ("order_17", $order_17, '', 4); 741 html_print_input_text ("custom_oid_data_17", $custom_oid_data_17, '', 60); 742 echo '</td></tr>'; 743 744 // Variable bindings/Data #18 745 echo '<tr id="tr-custom_value"><td class="datos" valign="top">'.__('Variable bindings/Data'); 746 echo '</td><td class="datos">'; 747 echo '#'; 748 html_print_input_text ("order_18", $order_18, '', 4); 749 html_print_input_text ("custom_oid_data_18", $custom_oid_data_18, '', 60); 750 echo '</td></tr>'; 751 752 // Variable bindings/Data #19 753 echo '<tr id="tr-custom_value"><td class="datos" valign="top">'.__('Variable bindings/Data'); 754 echo '</td><td class="datos">'; 755 echo '#'; 756 html_print_input_text ("order_19", $order_19, '', 4); 757 html_print_input_text ("custom_oid_data_19", $custom_oid_data_19, '', 60); 758 echo '</td></tr>'; 759 760 // Variable bindings/Data #20 761 echo '<tr id="tr-custom_value"><td class="datos" valign="top">'.__('Variable bindings/Data'); 762 echo '</td><td class="datos">'; 763 echo '#'; 764 html_print_input_text ("order_20", $order_20, '', 4); 765 html_print_input_text ("custom_oid_data_20", $custom_oid_data_20, '', 60); 766 echo '</td></tr>'; 767 768 //Button 769 //echo '<tr><td></td><td align="right">'; 770 771 // End table 772 //echo "</td></tr></table>"; 773 774 // Alert configuration 775 776 //echo '<table cellpadding="4" cellspacing="4" width="98%" class="databox_color" style="border:1px solid #A9A9A9;">'; 777 778 //echo '<tr><td class="datos"><b>' . __('Alert configuration') . ui_print_help_icon("snmp_alert_configuration", true) . '</b></td></tr>'; 779 780 // Alert fields 781 782 $al = array( 783 'al_field1' => $al_field1, 784 'al_field2' => $al_field2, 785 'al_field3' => $al_field3, 786 'al_field4' => $al_field4, 787 'al_field5' => $al_field5, 788 'al_field6' => $al_field6, 789 'al_field7' => $al_field7, 790 'al_field8' => $al_field8, 791 'al_field9' => $al_field9, 792 'al_field10' => $al_field10); 793 794 // Hidden div with help hint to fill with javascript 795 html_print_div(array('id' => 'help_snmp_alert_hint', 'content' => ui_print_help_icon ("snmp_alert_field1", true), 'hidden' => true)); 796 797 for ($i = 1; $i <= 10; $i++) { 798 echo '<tr id="table_macros-field'.$i.'"><td class="datos" valign="top">'.html_print_image('images/spinner.gif',true); 799 echo '<td class="datos">' . html_print_image('images/spinner.gif',true); 800 html_print_input_hidden('field'.$i.'_value', isset($al['al_field'.$i]) ? $al['al_field'.$i] : ''); 801 echo '</td></tr>'; 802 } 803 804 // Max / Min alerts 805 echo '<tr><td class="datos2">' . __('Min. number of alerts').'</td><td class="datos2">'; 806 html_print_input_text ("min_alerts", $min_alerts, '', 3); 807 808 echo '</td></tr><tr><td class="datos">'.__('Max. number of alerts').'</td><td class="datos">'; 809 html_print_input_text ("max_alerts", $max_alerts, '', 3); 810 echo '</td></tr>'; 811 812 // Time Threshold 813 echo '<tr><td class="datos2">'.__('Time threshold').'</td><td class="datos2">'; 814 815 $fields = array (); 816 $fields[$time_threshold] = human_time_description_raw ($time_threshold); 817 $fields[SECONDS_5MINUTES] = human_time_description_raw (SECONDS_5MINUTES); 818 $fields[SECONDS_10MINUTES] = human_time_description_raw (SECONDS_10MINUTES); 819 $fields[SECONDS_15MINUTES] = human_time_description_raw (SECONDS_15MINUTES); 820 $fields[SECONDS_30MINUTES] = human_time_description_raw (SECONDS_30MINUTES); 821 $fields[SECONDS_1HOUR] = human_time_description_raw (SECONDS_1HOUR); 822 $fields[SECONDS_2HOUR] = human_time_description_raw (SECONDS_2HOUR); 823 $fields[SECONDS_5HOUR] = human_time_description_raw (SECONDS_5HOUR); 824 $fields[SECONDS_12HOURS] = human_time_description_raw (SECONDS_12HOURS); 825 $fields[SECONDS_1DAY] = human_time_description_raw (SECONDS_1DAY); 826 $fields[SECONDS_1WEEK] = human_time_description_raw (SECONDS_1WEEK); 827 $fields[-1] = __('Other value'); 828 829 html_print_select ($fields, "time_threshold", $time_threshold, '', '', '0', false, false, false, '" style="margin-right:60px'); 830 echo '<div id="div-time_other" style="display:none">'; 831 html_print_input_text ("time_other", 0, '', 6); 832 echo ' ' . __('seconds') . '</div></td></tr>'; 833 834 // Priority 835 echo '<tr><td class="datos">'.__('Priority').'</td><td class="datos">'; 836 echo html_print_select (get_priorities (), "priority", $priority, '', '', '0', false, false, false); 837 echo '</td></tr>'; 838 839 // Alert type (e-mail, event etc.) 840 echo '<tr><td class="datos">'.__('Alert action').'</td><td class="datos">'; 841 842 switch ($config['dbtype']) { 843 case "mysql": 844 case "postgresql": 845 html_print_select_from_sql( 846 'SELECT id, name 847 FROM talert_actions 848 ORDER BY name', 849 "alert_type", $alert_type, '', '', 0, false, false, false); 850 break; 851 case "oracle": 852 html_print_select_from_sql( 853 'SELECT id, dbms_lob.substr(name,4000,1) as name 854 FROM talert_actions 855 ORDER BY dbms_lob.substr(name,4000,1)', 856 "alert_type", $alert_type, '', '', 0, false, false, false); 857 break; 858 } 859 echo '</td></tr>'; 860 echo '<tr><td class="datos">' . __('Position') . 861 ui_print_help_icon ("snmp_alert_position", true) . 862 '</td><td class="datos">'; 863 864 html_print_input_text ("position", $position, '', 3); 865 echo '</td></tr>'; 866 echo '</table>'; 867 868 echo "<table style='width:100%'>"; 869 echo '<tr><td></td><td align="right">'; 870 if ($id_as > 0) { 871 html_print_submit_button (__('Update'), "submit", false, 'class="sub upd"', false); 872 } 873 else { 874 html_print_submit_button (__('Create'), "submit", false, 'class="sub wand"', false); 875 } 876 echo '</td></tr></table>'; 877 echo "</table>"; 878 echo "</form>"; 879} 880else { 881 require_once ('include/functions_alerts.php'); 882 883 $free_search = (string)get_parameter('free_search', ''); 884 $trap_type_filter = (int)get_parameter('trap_type_filter', SNMP_TRAP_TYPE_NONE); 885 $priority_filter = (int)get_parameter('priority_filter', -1); 886 $filter_param = (bool)get_parameter('filter', false); 887 $offset = (int) get_parameter ('offset'); 888 889 $table_filter = new stdClass(); 890 $table_filter->width = "100%"; 891 $table_filter->class = "databox filters"; 892 $table_filter->data = array(); 893 $table_filter->data[0][0] = __('Free search') . ui_print_help_tip( 894 __('Search by these fields description, OID, Custom Value, SNMP Agent (IP), Single value, each Variable bindings/Datas.'), true); 895 $table_filter->data[0][1] = 896 html_print_input_text('free_search', $free_search, '', 30, 100, true); 897 $table_filter->data[0][2] = __('Trap type'); 898 $table_filter->data[0][3] = 899 html_print_select ($trap_types, 'trap_type_filter', $trap_type_filter, '', '', '', true, false, false); 900 $table_filter->data[0][4] = __('Priority'); 901 $table_filter->data[0][5] = 902 html_print_select (get_priorities(), "priority_filter", $priority_filter, '', __('None'), '-1', true, false, false);; 903 904 $form_filter = '<form name="agente" method="post" action="index.php?sec=snmpconsole&sec2=godmode/snmpconsole/snmp_alert">'; 905 $form_filter .= html_print_input_hidden('filter', 1, true); 906 $form_filter .= html_print_table($table_filter, true); 907 $form_filter .= '<div style="text-align: right; width: ' . $table_filter->width . '">'; 908 $form_filter .= html_print_submit_button(__('Filter'), 'filter_button', false, 'class="sub filter"', true); 909 $form_filter .= '</div>'; 910 $form_filter .= '</form>'; 911 912 //echo "<br>"; 913 ui_toggle($form_filter,__('Alert SNMP control filter'), __('Toggle filter(s)')); 914 915 $filter = array(); 916 $offset = (int) get_parameter ('offset'); 917 $limit = (int) $config['block_size']; 918 if ($filter_param) { 919 //Move the first page 920 $offset = 0; 921 922 $url_pagination = "index.php?" . 923 "sec=snmpconsole&" . 924 "sec2=godmode/snmpconsole/snmp_alert&" . 925 "free_search=" . $free_search . "&" . 926 "trap_type_filter=" . $trap_type_filter . "&" . 927 "priority_filter=" . $priority_filter; 928 } 929 else { 930 $url_pagination = "index.php?" . 931 "sec=snmpconsole&" . 932 "sec2=godmode/snmpconsole/snmp_alert&" . 933 "free_search=" . $free_search . "&" . 934 "trap_type_filter=" . $trap_type_filter . "&" . 935 "priority_filter=" . $priority_filter . "&" . 936 "offset=" . $offset; 937 } 938 939 940 $where_sql = ""; 941 if (!empty($free_search)) { 942 switch ($config["dbtype"]) { 943 case "mysql": 944 case "postgresql": 945 //$where_sql = ' 1 = 1'; 946 if ($trap_type_filter != SNMP_TRAP_TYPE_NONE) { 947 $where_sql .= ' AND `trap_type` = ' . $trap_type_filter; 948 } 949 950 if ($priority_filter != -1) { 951 $where_sql .= ' AND `priority` = ' . $priority_filter; 952 } 953 $where_sql .= " AND (`single_value` LIKE '%" . $free_search . "%' 954 OR `_snmp_f10_` LIKE '%" . $free_search . "%' 955 OR `_snmp_f9_` LIKE '%" . $free_search . "%' 956 OR `_snmp_f8_` LIKE '%" . $free_search . "%' 957 OR `_snmp_f7_` LIKE '%" . $free_search . "%' 958 OR `_snmp_f6_` LIKE '%" . $free_search . "%' 959 OR `_snmp_f5_` LIKE '%" . $free_search . "%' 960 OR `_snmp_f4_` LIKE '%" . $free_search . "%' 961 OR `_snmp_f3_` LIKE '%" . $free_search . "%' 962 OR `_snmp_f2_` LIKE '%" . $free_search . "%' 963 OR `_snmp_f1_` LIKE '%" . $free_search . "%' 964 OR `oid` LIKE '%" . $free_search . "%' 965 OR `custom_oid` LIKE '%" . $free_search . "%' 966 OR `agent` LIKE '%" . $free_search . "%' 967 OR `description` LIKE '%" . $free_search . "%')"; 968 break; 969 case "oracle": 970 //$where_sql = ' 1 = 1'; 971 if ($trap_type_filter != SNMP_TRAP_TYPE_NONE) { 972 $where_sql .= ' AND trap_type = ' . $trap_type_filter; 973 } 974 975 if ($priority_filter != -1) { 976 $where_sql .= ' AND priority = ' . $priority_filter; 977 } 978 $where_sql .= " AND (single_value LIKE '%" . $free_search . "%' 979 OR \"_snmp_f10_\" LIKE '%" . $free_search . "%' 980 OR \"_snmp_f9_\" LIKE '%" . $free_search . "%' 981 OR \"_snmp_f8_\" LIKE '%" . $free_search . "%' 982 OR \"_snmp_f7_\" LIKE '%" . $free_search . "%' 983 OR \"_snmp_f6_\" LIKE '%" . $free_search . "%' 984 OR \"_snmp_f5_\" LIKE '%" . $free_search . "%' 985 OR \"_snmp_f4_\" LIKE '%" . $free_search . "%' 986 OR \"_snmp_f3_\" LIKE '%" . $free_search . "%' 987 OR \"_snmp_f2_\" LIKE '%" . $free_search . "%' 988 OR \"_snmp_f1_\" LIKE '%" . $free_search . "%' 989 OR oid LIKE '%" . $free_search . "%' 990 OR custom_oid LIKE '%" . $free_search . "%' 991 OR agent LIKE '%" . $free_search . "%' 992 OR description LIKE '%" . $free_search . "%')"; 993 break; 994 } 995 } 996 997 $count = db_get_value_sql("SELECT COUNT(*) 998 FROM talert_snmp WHERE id_group IN ($str_user_groups) " . 999 $where_sql); 1000 1001 $result = array(); 1002 1003 //Overview 1004 if ($count == 0) { 1005 $result = array (); 1006 ui_print_info_message ( array('no_close'=>true, 'message'=> __('There are no SNMP alerts') ) ); 1007 } 1008 else { 1009 ui_pagination ($count, $url_pagination); 1010 switch ($config["dbtype"]) { 1011 case "mysql": 1012 case "postgresql": 1013 $where_sql .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; 1014 $result = db_get_all_rows_sql("SELECT * 1015 FROM talert_snmp 1016 WHERE id_group IN ($str_user_groups) " . $where_sql); 1017 break; 1018 case "oracle": 1019 $sql = "SELECT * 1020 FROM talert_snmp 1021 WHERE id_group IN ($str_user_groups) " . $where_sql; 1022 $set = array(); 1023 if (isset($offset) && isset($limit)) { 1024 $set['limit'] = $limit; 1025 $set['offset'] = $offset; 1026 } 1027 $result = oracle_recode_query ($sql, $set, 'AND', false); 1028 break; 1029 } 1030 } 1031 1032 $table = new stdClass(); 1033 $table->data = array (); 1034 $table->head = array (); 1035 $table->size = array (); 1036 $table->cellpadding = 4; 1037 $table->cellspacing = 4; 1038 $table->width = "100%"; 1039 $table->class= "databox data"; 1040 $table->align = array (); 1041 1042 $table->head[0] = '<span title="' . __('Position') . '">' . __('P.') . '</span>'; 1043 $table->align[0] = 'left'; 1044 1045 $table->head[1] = __('Alert action'); 1046 1047 $table->head[2] = __('SNMP Agent'); 1048 $table->size[2] = "90px"; 1049 $table->align[2] = 'left'; 1050 1051 $table->head[3] = __('Enterprise String'); 1052 $table->align[3] = 'left'; 1053 1054 $table->head[4] = __('Custom Value/Enterprise String'); 1055 $table->align[4] = 'left'; 1056 1057 $table->head[5] = __('Description'); 1058 1059 $table->head[6] = '<span title="' . __('Times fired') . '">' . __('TF.') . '</span>'; 1060 $table->size[6] = "50px"; 1061 $table->align[6] = 'left'; 1062 1063 $table->head[7] = __('Last fired'); 1064 $table->align[7] = 'left'; 1065 1066 $table->head[8] = __('Action'); 1067 $table->size[8] = "90px"; 1068 $table->align[8] = 'left'; 1069 1070 $table->head[9] = html_print_checkbox ("all_delete_box", "1", false, true); 1071 $table->size[9] = "10px"; 1072 $table->align[9] = 'left'; 1073 1074 foreach ($result as $row) { 1075 $data = array (); 1076 $data[0] = $row["position"]; 1077 1078 $url = "index.php?" . 1079 "sec=snmpconsole&" . 1080 "sec2=godmode/snmpconsole/snmp_alert&" . 1081 "id_alert_snmp=" . $row["id_as"] ."&" . 1082 "update_alert=1"; 1083 $data[1] = '<table>'; 1084 $data[1] .= '<tr>'; 1085 $data[1] .= '<a href="' . $url . '">' . 1086 alerts_get_alert_action_name ($row["id_alert"]) . '</a>'; 1087 $other_actions = db_get_all_rows_filter('talert_snmp_action', array('id_alert_snmp'=>$row['id_as'])); 1088 $data[1] .= '</tr>'; 1089 1090 if ($other_actions != false) { 1091 foreach ($other_actions as $action) { 1092 $data[1] .= '<tr>'; 1093 $data[1] .= '<td>'. alerts_get_alert_action_name ($action["alert_type"]).'</td>'; 1094 $data[1] .= '<td> <a href="index.php?sec=snmpconsole&sec2=godmode/snmpconsole/snmp_alert&delete_action=1&action_id='.$action['id'].'" onClick="javascript:return confirm(\''.__('Are you sure?').'\')">' . 1095 html_print_image("images/cross.png", true, array("border" => '0', "alt" => __('Delete'))) . '</a> </td>'; 1096 $data[1] .= '</tr>'; 1097 } 1098 } 1099 $data[1] .= '</table>'; 1100 1101 $data[2] = $row["agent"]; 1102 $data[3] = $row["oid"]; 1103 $data[4] = $row["custom_oid"]; 1104 $data[5] = $row["description"]; 1105 $data[6] = $row["times_fired"]; 1106 1107 if (($row["last_fired"] != "1970-01-01 00:00:00") and ($row["last_fired"] != "01-01-1970 00:00:00")) { 1108 $data[7] = ui_print_timestamp($row["last_fired"], true); 1109 } 1110 else { 1111 $data[7] = __('Never'); 1112 } 1113 1114 $data[8] = '<a href="index.php?' . 1115 'sec=snmpconsole&' . 1116 'sec2=godmode/snmpconsole/snmp_alert&' . 1117 'update_alert=1&'. 1118 'id_alert_snmp='.$row["id_as"].'">' . 1119 html_print_image("images/config.png", true, array("border" => '0', "alt" => __('Update'))) . '</a>' . 1120 '<a href="javascript:show_add_action_snmp(\'' . $row['id_as'] . '\');">' . 1121 html_print_image('images/add.png', true, array('title' => __("Add action"))) . 1122 '</a>' . 1123 '<a href="index.php?sec=snmpconsole&sec2=godmode/snmpconsole/snmp_alert&delete_alert='.$row["id_as"].'" onClick="javascript:return confirm(\''.__('Are you sure?').'\')">' . 1124 html_print_image("images/cross.png", true, array("border" => '0', "alt" => __('Delete'))) . '</a>'; 1125 1126 1127 $data[9] = html_print_checkbox_extended("delete_ids[]", 1128 $row['id_as'], false, false, false, 'class="chk_delete"', true); 1129 1130 $idx = count ($table->data); //The current index of the table is 1 less than the count of table data so we count before adding to table->data 1131 array_push ($table->data, $data); 1132 1133 $table->rowclass[$idx] = get_priority_class ($row["priority"]); 1134 } 1135 1136 # DIALOG ADD MORE ACTIONS 1137 echo '<div id="add_action_snmp-div" style="display:none;text-align:left">'; 1138 1139 echo '<form id="add_action_form" method="post">'; 1140 echo '<table class="databox_color" style="width:100%">'; 1141 echo '<tr>'; 1142 echo '<td class="datos2" style="font-weight:bold;padding:6px;">'; 1143 echo __('ID Alert SNMP'); 1144 echo '</td>'; 1145 echo '<td class="datos">'; 1146 html_print_input_text('id_alert_snmp', '', '', 3,10,false,true); 1147 echo '</td>'; 1148 echo '</tr>'; 1149 echo '<tr class="datos2">'; 1150 echo '<td class="datos2" style="font-weight:bold;padding:6px;">'; 1151 echo __('Action'); 1152 echo '</td>'; 1153 echo '<td class="datos2">'; 1154 1155 switch ($config['dbtype']) { 1156 case "mysql": 1157 case "postgresql": 1158 html_print_select_from_sql( 1159 'SELECT id, name 1160 FROM talert_actions 1161 ORDER BY name', 1162 "alert_type", $alert_type, '', '', 0, false, false, false); 1163 break; 1164 case "oracle": 1165 html_print_select_from_sql( 1166 'SELECT id, dbms_lob.substr(name,4000,1) as name 1167 FROM talert_actions 1168 ORDER BY dbms_lob.substr(name,4000,1)', 1169 "alert_type", $alert_type, '', '', 0, false, false, false); 1170 break; 1171 } 1172 echo '</td>'; 1173 echo '</tr>'; 1174 1175 $al = array( 1176 'al_field1' => $al_field1, 1177 'al_field2' => $al_field2, 1178 'al_field3' => $al_field3, 1179 'al_field4' => $al_field4, 1180 'al_field5' => $al_field5, 1181 'al_field6' => $al_field6, 1182 'al_field7' => $al_field7, 1183 'al_field8' => $al_field8, 1184 'al_field9' => $al_field9, 1185 'al_field10' => $al_field10); 1186 1187 for ($i = 1; $i <= 10; $i++) { 1188 echo '<tr id="table_macros-field'.$i.'"><td class="datos" valign="top">'.html_print_image('images/spinner.gif',true); 1189 echo '<td class="datos">' . html_print_image('images/spinner.gif',true); 1190 html_print_input_hidden('field'.$i.'_value', isset($al['al_field'.$i]) ? $al['al_field'.$i] : ''); 1191 echo '</td>'; 1192 echo '</tr>'; 1193 } 1194 1195 html_print_div(array('id' => 'help_snmp_alert_hint', 'content' => ui_print_help_icon ("snmp_alert_field1", true), 'hidden' => true)); 1196 1197 echo '</table>'; 1198 html_print_input_hidden('add_alert', 1); 1199 echo html_print_submit_button (__('Add'), 'addbutton', false, array('class' => "sub next", 'style' => "float:right"), true); 1200 echo '</form>'; 1201 echo '</div>'; 1202 # END DIALOG ADD MORE ACTIONS 1203 1204 1205 if (!empty ($table->data)) { 1206 echo '<form name="agente" method="post" action="index.php?sec=snmpconsole&sec2=godmode/snmpconsole/snmp_alert">'; 1207 html_print_table ($table); 1208 1209 ui_pagination ($count, $url_pagination); 1210 1211 echo '<div style="float:right; margin-left: 10px;">'; 1212 html_print_input_hidden('multiple_delete', 1); 1213 html_print_submit_button(__('Delete selected'), 'delete_button', false, 'class="sub delete"'); 1214 echo '</div>'; 1215 echo '</form>'; 1216 } 1217 1218 echo '<div style="float:right;">'; 1219 echo '<form name="agente" method="post" action="index.php?sec=snmpconsole&sec2=godmode/snmpconsole/snmp_alert">'; 1220 html_print_input_hidden('create_alert', 1); 1221 html_print_submit_button (__('Create'), "alert", false, 'class="sub next"'); 1222 echo "</form></div>"; 1223 1224 echo '<div style="margin-left: 30px; line-height: 17px; vertical-align: top; width:120px;">'; 1225 echo '<h3>'.__('Legend').'</h3>'; 1226 foreach (get_priorities() as $num => $name) { 1227 echo '<span class="' . get_priority_class ($num).'">' . $name . '</span>'; 1228 echo '<br />'; 1229 } 1230 echo '</div>'; 1231 1232 unset ($table); 1233} 1234 1235ui_require_javascript_file('tiny_mce', 'include/javascript/tiny_mce/'); 1236?> 1237<script language="javascript" type="text/javascript"> 1238 1239function time_changed () { 1240 var time = this.value; 1241 if (time == -1) { 1242 $('#time_threshold').fadeOut ('normal', function () { 1243 $('#div-time_other').fadeIn ('normal'); 1244 }); 1245 } 1246} 1247 1248$(document).ready (function () { 1249 $('#time_threshold').change (time_changed); 1250 1251 $("input[name=all_delete_box]").change (function() { 1252 if ($(this).is(":checked")) { 1253 $("input[name='delete_ids[]']").check(); 1254 } 1255 else { 1256 $("input[name='delete_ids[]']").uncheck(); 1257 } 1258 }); 1259 1260 $("#alert_type").change (function () { 1261 values = Array (); 1262 values.push ({ 1263 name: "page", 1264 value: "godmode/alerts/alert_commands" 1265 }); 1266 values.push ({ 1267 name: "get_alert_command", 1268 value: "1" 1269 }); 1270 values.push ({ 1271 name: "id_action", 1272 value: this.value 1273 }); 1274 1275 values.push ({ 1276 name: "get_recovery_fields", 1277 value: "0" 1278 }); 1279 jQuery.get ( 1280 <?php 1281 echo "'" . ui_get_full_url("ajax.php", false, false, false) . "'"; 1282 ?>, 1283 values, 1284 function (data, status) { 1285 original_command = js_html_entity_decode (data["command"]); 1286 command_description = js_html_entity_decode (data["description"]); 1287 for (i = 1; i <= 10; i++) { 1288 var old_value = ''; 1289 // Only keep the value if is provided from hidden (first time) 1290 1291 var id_field = $("[name=field" + i + "_value]").attr('id'); 1292 1293 if (id_field == "hidden-field" + i + "_value") { 1294 old_value = $("[name=field" + i + "_value]").val(); 1295 } 1296 1297 // If the row is empty, hide de row 1298 if (data["fields_rows"][i] == '') { 1299 $('#table_macros-field' + i).hide(); 1300 } 1301 else { 1302 $('#table_macros-field' + i).replaceWith(data["fields_rows"][i]); 1303 1304 // The row provided has a predefined class. We delete it 1305 $('#table_macros-field' + i) 1306 .removeAttr('class'); 1307 1308 //Remove this to put the help message in alert commands, to do it more general 1309 // Add help hint only in first field 1310 /*if (i == 1) { 1311 var td_content = 1312 $('#table_macros-field' + i) 1313 .find('td').eq(0); 1314 1315 td_content 1316 .html( 1317 td_content.html() + 1318 $('#help_snmp_alert_hint').html() 1319 ); 1320 }*/ 1321 1322 $("[name=field" + i + "_value]").val(old_value); 1323 $('#table_macros-field').show(); 1324 } 1325 } 1326 }, 1327 "json" 1328 ); 1329 }); 1330 1331 // Charge the fields of the action 1332 $("#alert_type").trigger('change'); 1333 1334 $("#submit-delete_button").click (function () { 1335 confirmation = confirm("<?php echo __('Are you sure?'); ?>"); 1336 if (!confirmation) { 1337 return; 1338 } 1339 }); 1340 1341 tinyMCE.init({ 1342 selector: 'textarea.tiny-mce-editor', 1343 theme : "advanced", 1344 plugins : "preview, print, table, searchreplace, nonbreaking, xhtmlxtras, noneditable", 1345 theme_advanced_buttons1 : "bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsize,select", 1346 theme_advanced_buttons2 : "search,replace,|,bullist,numlist,|,undo,redo,|,link,unlink,image,|,cleanup,code,preview,|,forecolor,backcolor", 1347 theme_advanced_buttons3 : "", 1348 theme_advanced_toolbar_location : "top", 1349 theme_advanced_toolbar_align : "left", 1350 theme_advanced_resizing : true, 1351 theme_advanced_statusbar_location : "bottom", 1352 force_p_newlines : false, 1353 forced_root_block : '', 1354 inline_styles : true, 1355 valid_children : "+body[style]", 1356 element_format : "html" 1357 }); 1358 1359}); 1360 1361function show_add_action_snmp(id_alert_snmp) { 1362 1363 $("#add_action_snmp-div").hide() 1364 .dialog ({ 1365 resizable: true, 1366 draggable: true, 1367 title: '<?php echo __('Add action '); ?>', 1368 modal: true, 1369 overlay: { 1370 opacity: 0.5, 1371 background: "black" 1372 }, 1373 width: 550, 1374 height: 400 1375 }) 1376 .show (); 1377 $("#text-id_alert_snmp").val(id_alert_snmp); 1378} 1379</script> 1380