1<?php 2 3// Pandora FMS - http://pandorafms.com 4// ================================================== 5// Copyright (c) 2005-2010 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// Load globar vars 17global $config; 18 19//Ajax tooltip to deploy modules's tag info. 20if (is_ajax ()) { 21 $get_tag_tooltip = (bool) get_parameter ('get_tag_tooltip', 0); 22 $get_relations_tooltip = (bool) get_parameter ('get_relations_tooltip', 0); 23 24 25 if ($get_tag_tooltip) { 26 $id_agente_modulo = (int) get_parameter ('id_agente_modulo'); 27 if ($id_agente_modulo == false) 28 return; 29 $tags = tags_get_module_tags($id_agente_modulo); 30 31 32 if ($tags === false) 33 $tags = array(); 34 35 echo '<h3>' . __("Tag's information") . '</h3>'; 36 echo "<table border='0'>"; 37 foreach ($tags as $tag) { 38 echo "<tr>"; 39 40 echo "<td>"; 41 if (tags_get_module_policy_tags($tag, $id_agente_modulo)) { 42 html_print_image('images/policies.png', false, array('style' => 'vertical-align: middle;')); 43 } 44 echo "</td>"; 45 46 echo "<td>"; 47 echo tags_get_name($tag); 48 echo "</td>"; 49 50 echo "</tr>"; 51 } 52 echo "</table>"; 53 54 return; 55 } 56 57 58 if ($get_relations_tooltip) { 59 $id_agente_modulo = (int) get_parameter ('id_agente_modulo'); 60 if ($id_agente_modulo == false) 61 return; 62 $id_agente = modules_get_agentmodule_agent($id_agente_modulo); 63 64 $params = array( 65 'id_agent' => $id_agente, 66 'id_module' => $id_agente_modulo 67 ); 68 $relations = modules_get_relations($params); 69 70 if (empty($relations)) 71 return; 72 73 $table_relations = new stdClass(); 74 $table_relations->id = 'module_' . $id_agente_modulo . '_relations'; 75 $table_relations->width = '100%'; 76 $table_relations->class = 'databox filters'; 77 $table_relations->style = array(); 78 $table_relations->style[0] = 'font-weight: bold;'; 79 $table_relations->style[2] = 'font-weight: bold;'; 80 $table_relations->head = array(); 81 $table_relations->head[0] = __("Relationship information"); 82 $table_relations->head_colspan[0] = 4; 83 $table_relations->data = array(); 84 85 foreach ($relations as $relation) { 86 if ($relation['module_a'] == $id_agente_modulo) { 87 $id_module = $relation['module_b']; 88 } 89 else { 90 $id_module = $relation['module_a']; 91 } 92 $id_agent = modules_get_agentmodule_agent($id_module); 93 94 $data = array(); 95 $data[0] = __('Agent'); 96 $data[1] = ui_print_agent_name ($id_agent, true); 97 $data[2] = __('Module'); 98 $data[3] = "<a href='index.php?sec=gagente&sec2=godmode/agentes/configurar_agente 99 &id_agente=$id_agent&tab=module&edit_module=1&id_agent_module=$id_module'>" . 100 ui_print_truncate_text(modules_get_agentmodule_name($id_module), 'module_medium', true, true, true, '[…]') . "</a>"; 101 $table_relations->data[] = $data; 102 } 103 html_print_table($table_relations); 104 105 return; 106 } 107 return; 108} 109 110if (!isset ($id_agente)) { 111 //This page is included, $id_agente should be passed to it. 112 db_pandora_audit("HACK Attempt", 113 "Trying to get the monitor list without id_agent passed"); 114 include ("general/noaccess.php"); 115 exit; 116} 117 118$id_agent = (int)get_parameter('id_agente'); 119$status_filter_monitor = (int)get_parameter('status_filter_monitor', -1); 120$status_text_monitor = get_parameter('status_text_monitor', ''); 121 122echo "<h4 style='padding-top:0px !important;'>"; 123 124echo ui_print_help_tip(__('To see the list of modules paginated, enable this option in the Styles Configuration.'), true) . 125 __('Full list of monitors') . ' ' . 126 reporting_tiny_stats ($agent, true, 'modules'); 127 128$modules_not_init = agents_monitor_notinit($id_agente); 129if (!empty($modules_not_init)) { 130 echo clippy_context_help("modules_not_init"); 131} 132echo "</h4>"; 133 134 135ob_start(); 136 137 138print_form_filter_monitors($id_agente, $status_filter_monitor, $status_text_monitor); 139 140echo "<div id='module_list_loading'>" . 141 html_print_image('images/spinner.gif', true) . 142 '</div>'; 143echo "<div id='module_list'>" . 144 145 "</div>"; 146 147 148$html_toggle = ob_get_clean(); 149ui_toggle($html_toggle, 150 __('List of modules'), 151 'status_monitor_agent', 152 false); 153 154?> 155<script type="text/javascript"> 156 var sort_field = 'name'; 157 var sort_rows = 'up'; 158 var filter_status = -1; 159 var filter_text = ""; 160 reset_filter_modules (); 161 162 $(document).ready(function() { 163 var parameters = {}; 164 165 parameters["list_modules"] = 1; 166 parameters["id_agente"] = <?php echo $id_agente; ?>; 167 parameters["page"] = "include/ajax/module"; 168 169 jQuery.ajax ({ 170 data: parameters, 171 type: 'POST', 172 url: "ajax.php", 173 dataType: 'html', 174 success: function (data) { 175 $("#module_list_loading").hide(); 176 177 $("#module_list").empty(); 178 $("#module_list").html(data); 179 } 180 }); 181 }); 182 183 function order_module_list(sort_field_param, sort_rows_param) { 184 sort_field = sort_field_param; 185 sort_rows = sort_rows_param; 186 187 var parameters = {}; 188 189 parameters["list_modules"] = 1; 190 parameters["id_agente"] = <?php echo $id_agente; ?>; 191 parameters["sort_field"] = sort_field; 192 parameters["sort"] = sort_rows; 193 parameters["status_filter_monitor"] = filter_status; 194 parameters["status_text_monitor"] = filter_text; 195 parameters["status_module_group"] = filter_group; 196 parameters["page"] = "include/ajax/module"; 197 198 199 $("#module_list").empty(); 200 $("#module_list_loading").show(); 201 202 203 jQuery.ajax ({ 204 data: parameters, 205 type: 'POST', 206 url: "ajax.php", 207 dataType: 'html', 208 success: function (data) { 209 $("#module_list_loading").hide(); 210 211 $("#module_list").empty(); 212 $("#module_list").html(data); 213 } 214 }); 215 } 216 217 function filter_modules() { 218 filter_status = $("#status_filter_monitor").val(); 219 filter_group = $("#status_module_group").val(); 220 filter_text = $("input[name='status_text_monitor']").val(); 221 222 var parameters = {}; 223 224 parameters["list_modules"] = 1; 225 parameters["id_agente"] = <?php echo $id_agente; ?>; 226 parameters["sort_field"] = sort_field; 227 parameters["sort"] = sort_rows; 228 parameters["status_filter_monitor"] = filter_status; 229 parameters["status_text_monitor"] = filter_text; 230 parameters["status_module_group"] = filter_group; 231 parameters["filter_monitors"] = 1; 232 parameters["monitors_change_filter"] = 1; 233 parameters["page"] = "include/ajax/module"; 234 235 236 $("#module_list").empty(); 237 $("#module_list_loading").show(); 238 239 240 jQuery.ajax ({ 241 data: parameters, 242 type: 'POST', 243 url: "ajax.php", 244 dataType: 'html', 245 success: function (data) { 246 $("#module_list_loading").hide(); 247 248 $("#module_list").empty(); 249 $("#module_list").html(data); 250 } 251 }); 252 } 253 254 function reset_filter_modules() { 255 $("#status_filter_monitor").val(-1); 256 $("#status_module_group").val(-1); 257 $("input[name='status_text_monitor']").val(""); 258 259 filter_modules(); 260 } 261 262 function pagination_list_modules(offset) { 263 var parameters = {}; 264 265 parameters["list_modules"] = 1; 266 parameters["id_agente"] = <?php echo $id_agente; ?>; 267 parameters["offset"] = offset; 268 parameters["sort_field"] = sort_field; 269 parameters["sort"] = sort_rows; 270 parameters["status_filter_monitor"] = filter_status; 271 parameters["status_text_monitor"] = filter_text; 272 parameters["status_module_group"] = filter_group; 273 parameters["filter_monitors"] = 0; 274 parameters["monitors_change_filter"] = 0; 275 parameters["page"] = "include/ajax/module"; 276 277 278 $("#module_list").empty(); 279 $("#module_list_loading").show(); 280 281 282 jQuery.ajax ({ 283 data: parameters, 284 type: 'POST', 285 url: "ajax.php", 286 dataType: 'html', 287 success: function (data) { 288 $("#module_list_loading").hide(); 289 290 $("#module_list").empty(); 291 $("#module_list").html(data); 292 } 293 }); 294 } 295</script> 296<?php 297 298ui_require_css_file ('cluetip'); 299ui_require_jquery_file ('cluetip'); 300 301echo "<div id='module_details_dialog' style='display: none;'></div>"; 302 303ui_include_time_picker(); 304ui_require_jquery_file("ui.datepicker-" . get_user_language(), "include/javascript/i18n/"); 305?> 306 307<script type="text/javascript"> 308/* <![CDATA[ */ 309 $("a.tag_details").cluetip ({ 310 arrows: true, 311 clickThrough: false, 312 attribute: 'href', 313 cluetipClass: 'default' 314 }); 315 $("a.relations_details").cluetip ({ 316 width: 500, 317 arrows: true, 318 clickThrough: false, 319 attribute: 'href', 320 cluetipClass: 'default', 321 sticky: true, 322 mouseOutClose: 'both', 323 closeText: '<?php html_print_image("images/cancel.png") ?>' 324 }); 325 326 // Show the modal window of an module 327 function show_module_detail_dialog(module_id, id_agent, server_name, offset, period,module_name) { 328 329 var server_name = ''; 330 var extra_parameters = ''; 331 if ($('input[name=selection_mode]:checked').val()) { 332 333 period = $('#period').val(); 334 335 var selection_mode = $('input[name=selection_mode]:checked').val(); 336 var date_from = $('#text-date_from').val(); 337 var time_from = $('#text-time_from').val(); 338 var date_to = $('#text-date_to').val(); 339 var time_to = $('#text-time_to').val(); 340 341 extra_parameters = '&selection_mode=' + selection_mode + '&date_from=' + date_from + '&date_to=' + date_to + '&time_from=' + time_from + '&time_to=' + time_to; 342 } 343 title = <?php echo "\"" . __("Module: ") . "\"" ?>; 344 $.ajax({ 345 type: "POST", 346 url: "<?php echo ui_get_full_url('ajax.php', false, false, false); ?>", 347 data: "page=include/ajax/module&get_module_detail=1&server_name="+server_name+"&id_agent="+id_agent+"&id_module=" + module_id+"&offset="+offset+"&period="+period + extra_parameters, 348 dataType: "html", 349 success: function(data) { 350 $("#module_details_dialog").hide () 351 .empty () 352 .append (data) 353 .dialog ({ 354 resizable: true, 355 draggable: true, 356 modal: true, 357 title: title + module_name, 358 overlay: { 359 opacity: 0.5, 360 background: "black" 361 }, 362 width: 650, 363 height: 500 364 }) 365 .show (); 366 refresh_pagination_callback (module_id, id_agent, "",module_name); 367 datetime_picker_callback(); 368 forced_title_callback(); 369 } 370 }); 371 } 372 function datetime_picker_callback() { 373 374 $("#text-time_from, #text-time_to").timepicker({ 375 showSecond: true, 376 timeFormat: '<?php echo TIME_FORMAT_JS; ?>', 377 timeOnlyTitle: '<?php echo __('Choose time');?>', 378 timeText: '<?php echo __('Time');?>', 379 hourText: '<?php echo __('Hour');?>', 380 minuteText: '<?php echo __('Minute');?>', 381 secondText: '<?php echo __('Second');?>', 382 currentText: '<?php echo __('Now');?>', 383 closeText: '<?php echo __('Close');?>'}); 384 385 $("#text-date_from, #text-date_to").datepicker({dateFormat: "<?php echo DATE_FORMAT_JS; ?>"}); 386 387 $.datepicker.setDefaults($.datepicker.regional[ "<?php echo get_user_language(); ?>"]); 388 } 389 datetime_picker_callback(); 390 391 function refresh_pagination_callback (module_id, id_agent, server_name,module_name) { 392 $(".binary_dialog").click( function() { 393 394 var classes = $(this).attr('class'); 395 classes = classes.split(' '); 396 var offset_class = classes[2]; 397 offset_class = offset_class.split('_'); 398 var offset = offset_class[1]; 399 400 var period = $('#period').val(); 401 402 show_module_detail_dialog(module_id, id_agent, server_name, offset, period,module_name); 403 return false; 404 }); 405 } 406/* ]]> */ 407</script> 408<?php 409function print_form_filter_monitors($id_agent, $status_filter_monitor = -1, 410 $status_text_monitor = '', $status_module_group=-1) { 411 412 $form_text = ''; 413 $table = new stdClass(); 414 $table->class = "databox filters"; 415 $table->width = "100%"; 416 $table->style[0] = 'font-weight: bold;'; 417 $table->style[2] = 'font-weight: bold;'; 418 $table->style[4] = 'font-weight: bold;'; 419 $table->data[0][0] = html_print_input_hidden('filter_monitors', 1, true); 420 $table->data[0][0] .= html_print_input_hidden('monitors_change_filter', 1, true); 421 $table->data[0][0] .= __('Status:'); 422 $status_list = array( 423 -1 => __('All'), 424 AGENT_MODULE_STATUS_CRITICAL_BAD => __('Critical'), 425 AGENT_MODULE_STATUS_CRITICAL_ALERT => __('Alert'), 426 AGENT_MODULE_STATUS_NORMAL => __('Normal'), 427 AGENT_MODULE_STATUS_NOT_NORMAL => __('Not Normal'), 428 AGENT_MODULE_STATUS_WARNING => __('Warning'), 429 AGENT_MODULE_STATUS_UNKNOWN => __('Unknown')); 430 431 $table->data[0][1] = html_print_select ($status_list, 432 'status_filter_monitor', $status_filter_monitor, '', '', 0, 433 true); 434 435 $table->data[0][2] = __('Free text for search (*):') . ui_print_help_tip( 436 __('Search by module name, list matches.'),true); 437 438 $table->data[0][3] = html_print_input_text('status_text_monitor', $status_text_monitor, '', 30, 100, true); 439 $table->data[0][4] = __('Module group'); 440 $rows = db_get_all_rows_sql("SELECT * 441 FROM tmodule_group where id_mg in (SELECT id_module_group from tagente_modulo where id_agente = $id_agent ) ORDER BY name"); 442 443 if (!empty($rows)) { 444 $rows_select[-1] = __('All'); 445 foreach ($rows as $module_group) 446 $rows_select[$module_group['id_mg']] = __($module_group['name']); 447 } 448 $table->data[0][5] = html_print_select ($rows_select,'status_module_group', $status_module_group, '', '',0, true); 449 $table->data[0][6] = html_print_button(__('Filter'), 'filter', false, 'filter_modules();', 'class="sub search"', true); 450 $table->data[0][7] = ' ' . html_print_button(__('Reset'), 'filter', false, 'reset_filter_modules();', 'class="sub upd" style="margin-top:0px;"', true); 451 $form_text .= html_print_table($table, true); 452 453 $filter_hidden = false; 454 455 if ($status_filter_monitor == -1 && $status_text_monitor == '' && $status_module_group == -1 ) { 456 $filter_hidden = true; 457 } 458 459 echo $form_text; 460} 461?> 462