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 Lesser General Public License 10// as published by the Free Software Foundation; version 2 11 12// This program is distributed in the hope that it will be useful, 13// but WITHOUT ANY WARRANTY; without even the implied warranty of 14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15// GNU General Public License for more details. 16 17/** 18 * @package Include 19 * @subpackage Reporting 20 */ 21 22/** 23 * Include the usual functions 24 */ 25require_once($config["homedir"] . "/include/functions.php"); 26require_once($config["homedir"] . "/include/functions_db.php"); 27require_once($config["homedir"] . "/include/functions_agents.php"); 28include_once($config["homedir"] . "/include/functions_groups.php"); 29require_once($config["homedir"] . '/include/functions_graph.php'); 30include_once($config['homedir'] . "/include/functions_modules.php"); 31include_once($config['homedir'] . "/include/functions_events.php"); 32include_once($config['homedir'] . "/include/functions_alerts.php"); 33include_once($config['homedir'] . '/include/functions_users.php'); 34enterprise_include_once('include/functions_metaconsole.php'); 35enterprise_include_once('include/functions_inventory.php'); 36include_once($config['homedir'] . "/include/functions_forecast.php"); 37include_once($config['homedir'] . "/include/functions_ui.php"); 38include_once($config['homedir'] . "/include/functions_netflow.php"); 39 40function reporting_html_header(&$table, $mini, $title, $subtitle, 41 $period, $date, $from, $to) { 42 43 global $config; 44 45 46 if ($mini) { 47 $sizh = ''; 48 $sizhfin = ''; 49 } 50 else { 51 $sizh = '<h4>'; 52 $sizhfin = '</h4>'; 53 } 54 55 56 $date_text = ""; 57 if (!empty($date)) { 58 $date_text = date($config["date_format"], $date); 59 } 60 else if (!empty($from) && !empty($to)) { 61 $date_text = 62 "(" . human_time_description_raw ($period) . ") " . 63 __("From:") . " " . date($config["date_format"], $from) . "<br />" . 64 __("To:") . " " . date($config["date_format"], $to); 65 } 66 else if ($period > 0) { 67 $date_text = human_time_description_raw($period); 68 } 69 else if ($period === 0) { 70 $date_text = __('Last data'); 71 } 72 73 74 $data = array(); 75 if (empty($subtitle) && (empty($date_text))) { 76 $data[] = $sizh . $title . $sizhfin; 77 $table->colspan[0][0] = 3; 78 } 79 else if (empty($subtitle)) { 80 $data[] = $sizh . $title . $sizhfin; 81 $data[] = "<div style='text-align: right;'>" . $sizh . $date_text . $sizhfin . "</div>"; 82 $table->colspan[0][1] = 2; 83 } 84 else if (empty($date_text)) { 85 $data[] = $sizh . $title . $sizhfin; 86 $data[] = $sizh . $subtitle . $sizhfin; 87 $table->colspan[0][1] = 2; 88 } 89 else { 90 $data[] = $sizh . $title . $sizhfin; 91 $data[] = $sizh . $subtitle . $sizhfin; 92 $data[] = "<div style='text-align: right;'>" . $sizh . $date_text . $sizhfin . "</div>"; 93 } 94 95 array_push ($table->data, $data); 96} 97 98function reporting_html_print_report($report, $mini = false) { 99 100 foreach ($report['contents'] as $key => $item) { 101 $table = new stdClass(); 102 $table->size = array (); 103 $table->style = array (); 104 $table->width = '100%'; 105 $table->class = 'databox filters'; 106 $table->rowclass = array (); 107 $table->rowclass[0] = 'datos3'; 108 $table->data = array (); 109 $table->head = array (); 110 $table->style = array (); 111 $table->colspan = array (); 112 $table->rowstyle = array (); 113 114 115 reporting_html_header($table, 116 $mini, $item['title'], 117 $item['subtitle'], 118 $item['date']['period'], 119 $item['date']['date'], 120 $item['date']['from'], 121 $item['date']['to']); 122 123 if ($item["description"] != "") { 124 $table->data['description_row']['description'] = $item["description"]; 125 $table->colspan['description_row']['description'] = 3; 126 } 127 128 switch ($item['type']) { 129 case 'availability': 130 reporting_html_availability($table, $item); 131 break; 132 case 'general': 133 reporting_html_general($table, $item); 134 break; 135 case 'sql': 136 reporting_html_sql($table, $item); 137 break; 138 case 'simple_graph': 139 reporting_html_graph($table, $item); 140 break; 141 case 'custom_graph': 142 reporting_html_graph($table, $item); 143 break; 144 case 'text': 145 reporting_html_text($table, $item); 146 break; 147 case 'url': 148 reporting_html_url($table, $item, $key); 149 break; 150 case 'max_value': 151 reporting_html_max_value($table, $item, $mini); 152 break; 153 case 'avg_value': 154 reporting_html_avg_value($table, $item, $mini); 155 break; 156 case 'min_value': 157 reporting_html_min_value($table, $item, $mini); 158 break; 159 case 'sumatory': 160 reporting_html_sum_value($table, $item, $mini); 161 break; 162 case 'MTTR': 163 reporting_html_MTTR_value($table, $item, $mini, true, true); 164 break; 165 case 'MTBF': 166 reporting_html_MTBF_value($table, $item, $mini, true, true); 167 break; 168 case 'TTO': 169 reporting_html_TTO_value($table, $item, $mini, false, true); 170 break; 171 case 'TTRT': 172 reporting_html_TTRT_value($table, $item, $mini, false, true); 173 break; 174 case 'agent_configuration': 175 reporting_html_agent_configuration($table, $item); 176 break; 177 case 'projection_graph': 178 reporting_html_graph($table, $item); 179 break; 180 case 'prediction_date': 181 reporting_html_prediction_date($table, $item, $mini); 182 break; 183 case 'simple_baseline_graph': 184 reporting_html_graph($table, $item); 185 break; 186 case 'netflow_area': 187 reporting_html_graph($table, $item); 188 break; 189 case 'netflow_pie': 190 reporting_html_graph($table, $item); 191 break; 192 case 'netflow_data': 193 reporting_html_graph($table, $item); 194 break; 195 case 'netflow_statistics': 196 reporting_html_graph($table, $item); 197 break; 198 case 'netflow_summary': 199 reporting_html_graph($table, $item); 200 break; 201 case 'monitor_report': 202 reporting_html_monitor_report($table, $item, $mini); 203 break; 204 case 'sql_graph_vbar': 205 reporting_html_sql_graph($table, $item); 206 break; 207 case 'sql_graph_hbar': 208 reporting_html_sql_graph($table, $item); 209 break; 210 case 'sql_graph_pie': 211 reporting_html_sql_graph($table, $item); 212 break; 213 case 'alert_report_module': 214 reporting_html_alert_report_module($table, $item); 215 break; 216 case 'alert_report_agent': 217 reporting_html_alert_report_agent($table, $item); 218 break; 219 case 'alert_report_group': 220 reporting_html_alert_report_group($table, $item); 221 break; 222 case 'network_interfaces_report': 223 reporting_html_network_interfaces_report($table, $item); 224 break; 225 case 'group_configuration': 226 reporting_html_group_configuration($table, $item); 227 break; 228 case 'historical_data': 229 reporting_html_historical_data($table, $item); 230 break; 231 case 'database_serialized': 232 reporting_html_database_serialized($table, $item); 233 break; 234 case 'agent_detailed_event': 235 case 'event_report_agent': 236 reporting_html_event_report_agent($table, $item); 237 break; 238 case 'group_report': 239 reporting_html_group_report($table, $item); 240 break; 241 case 'exception': 242 reporting_html_exception($table, $item); 243 break; 244 case 'agent_module': 245 reporting_html_agent_module($table, $item); 246 break; 247 case 'inventory': 248 reporting_html_inventory($table, $item); 249 break; 250 case 'inventory_changes': 251 reporting_html_inventory_changes($table, $item); 252 break; 253 case 'event_report_module': 254 reporting_html_event_report_module($table, $item); 255 break; 256 case 'event_report_group': 257 reporting_html_event_report_group($table, $item); 258 break; 259 case 'top_n': 260 reporting_html_top_n($table, $item); 261 break; 262 case 'SLA': 263 reporting_html_SLA($table, $item, $mini); 264 break; 265 case 'SLA_monthly': 266 reporting_enterprise_html_SLA_monthly($table, $item, $mini); 267 break; 268 case 'SLA_services': 269 reporting_enterprise_html_SLA_services($table, $item, $mini); 270 break; 271 } 272 273 if ($item['type'] == 'agent_module') 274 echo '<div style="width: 100%; overflow: auto;">'; 275 276 html_print_table($table); 277 278 if ($item['type'] == 'agent_module') 279 echo '</div>'; 280 } 281} 282 283function reporting_html_SLA($table, $item, $mini) { 284 if ($mini) { 285 $font_size = '1.5'; 286 } 287 else { 288 $font_size = '3'; 289 } 290 291 if (!empty($item['failed'])) { 292 $table->colspan['sla']['cell'] = 3; 293 $table->data['sla']['cell'] = $item['failed']; 294 } 295 else { 296 297 if (!empty($item['planned_downtimes'])) { 298 $downtimes_table = reporting_html_planned_downtimes_table($item['planned_downtimes']); 299 300 if (!empty($downtimes_table)) { 301 $table->colspan['planned_downtime']['cell'] = 3; 302 $table->data['planned_downtime']['cell'] = $downtimes_table; 303 } 304 } 305 306 $table1 = new stdClass(); 307 $table1->width = '99%'; 308 309 $table1->align = array(); 310 $table1->align[0] = 'left'; 311 $table1->align[1] = 'left'; 312 $table1->align[2] = 'right'; 313 $table1->align[3] = 'right'; 314 $table1->align[4] = 'right'; 315 $table1->align[5] = 'right'; 316 317 $table1->data = array (); 318 319 $table1->head = array (); 320 $table1->head[0] = __('Agent'); 321 $table1->head[1] = __('Module'); 322 $table1->head[2] = __('Max/Min Values'); 323 $table1->head[3] = __('SLA Limit'); 324 $table1->head[4] = __('SLA Compliance'); 325 $table1->head[5] = __('Status'); 326 327 $table1->headstyle = array(); 328 $table1->headstyle[2] = 'text-align: right'; 329 $table1->headstyle[3] = 'text-align: right'; 330 $table1->headstyle[4] = 'text-align: right'; 331 $table1->headstyle[5] = 'text-align: right'; 332 333 foreach ($item['data'] as $sla) { 334 $row = array(); 335 $row[] = $sla['agent']; 336 $row[] = $sla['module']; 337 $row[] = $sla['max'] . " / " . $sla['min']; 338 $row[] = round($sla['sla_limit'], 2) . "%"; 339 340 if ($sla['sla_value_unknown']) { 341 $row[] = '<span style="font: bold '.$font_size.'em Arial, Sans-serif; color: '.COL_UNKNOWN.';">' . 342 __('N/A') . '</span>'; 343 $row[] = '<span style="font: bold '.$font_size.'em Arial, Sans-serif; color: '.COL_UNKNOWN.';">' . 344 __('Unknown') . '</span>'; 345 } 346 elseif ($sla['sla_status']) { 347 $row[] = '<span style="font: bold '.$font_size.'em Arial, Sans-serif; color: '.COL_NORMAL.';">' . 348 round($sla['sla_value'], 2) . "%" . '</span>'; 349 $row[] = '<span style="font: bold '.$font_size.'em Arial, Sans-serif; color: '.COL_NORMAL.';">' . 350 __('OK') . '</span>'; 351 } 352 else { 353 $row[] = '<span style="font: bold '.$font_size.'em Arial, Sans-serif; color: '.COL_CRITICAL.';">' . 354 round($sla['sla_value'], 2) . "%" . '</span>'; 355 $row[] = '<span style="font: bold '.$font_size.'em Arial, Sans-serif; color: '.COL_CRITICAL.';">' . 356 __('Fail') . '</span>'; 357 } 358 359 $table1->data[] = $row; 360 } 361 362 $table->colspan['sla']['cell'] = 3; 363 $table->data['sla']['cell'] = html_print_table($table1, true); 364 365 if (!empty($item['charts'])) { 366 $table1 = new stdClass(); 367 $table1->width = '99%'; 368 369 $table1->data = array (); 370 371 foreach ($item['charts'] as $chart) { 372 $table1->data[] = array( 373 $chart['agent'] . "<br />" . $chart['module'], 374 $chart['chart']); 375 } 376 377 $table->colspan['charts']['cell'] = 3; 378 $table->data['charts']['cell'] = html_print_table($table1, true); 379 } 380 } 381} 382 383function reporting_html_top_n($table, $item) { 384 if (!empty($item['failed'])) { 385 $table->colspan['top_n']['cell'] = 3; 386 $table->data['top_n']['cell'] = $item['failed']; 387 } 388 else { 389 $table1 = new stdClass(); 390 $table1->width = '99%'; 391 392 $table1->align = array(); 393 $table1->align[0] = 'left'; 394 $table1->align[1] = 'left'; 395 $table1->align[2] = 'right'; 396 397 $table1->data = array (); 398 399 $table1->headstyle = array(); 400 $table1->headstyle[0] = 'text-align: left'; 401 $table1->headstyle[1] = 'text-align: left'; 402 $table1->headstyle[2] = 'text-align: right'; 403 404 $table1->head = array (); 405 $table1->head[0] = __('Agent'); 406 $table1->head[1] = __('Module'); 407 $table1->head[2] = __('Value'); 408 409 foreach ($item['data'] as $top) { 410 $row = array(); 411 $row[] = $top['agent']; 412 $row[] = $top['module']; 413 $row[] = $top['formated_value']; 414 $table1->data[] = $row; 415 } 416 417 $table->colspan['top_n']['cell'] = 3; 418 $table->data['top_n']['cell'] = html_print_table($table1, true); 419 420 if (!empty($item['charts']['pie'])) { 421 $table->colspan['char_pie']['cell'] = 3; 422 $table->data['char_pie']['cell'] = $item['charts']['pie']; 423 } 424 425 if (!empty($item['charts']['bars'])) { 426 $table->colspan['char_bars']['cell'] = 3; 427 $table->data['char_bars']['cell'] = $item['charts']['bars']; 428 } 429 430 if (!empty($item['resume'])) { 431 $table1 = new stdClass(); 432 $table1->width = '99%'; 433 434 $table1->align = array(); 435 $table1->align[0] = 'center'; 436 $table1->align[1] = 'center'; 437 $table1->align[2] = 'center'; 438 439 $table1->data = array (); 440 441 $table1->headstyle = array(); 442 $table1->headstyle[0] = 'text-align: center'; 443 $table1->headstyle[1] = 'text-align: center'; 444 $table1->headstyle[2] = 'text-align: center'; 445 446 $table1->head = array (); 447 $table1->head[0] = __('Min Value'); 448 $table1->head[1] = __('Average Value'); 449 $table1->head[2] = __('Max Value'); 450 451 $row = array(); 452 $row[] = $item['resume']['min']['formated_value']; 453 $row[] = $item['resume']['avg']['formated_value']; 454 $row[] = $item['resume']['max']['formated_value']; 455 $table1->data[] = $row; 456 457 $table->colspan['resume']['cell'] = 3; 458 $table->data['resume']['cell'] = html_print_table($table1, true); 459 } 460 } 461} 462 463function reporting_html_event_report_group($table, $item) { 464 global $config; 465 466 if (!empty($item['failed'])) { 467 $table->colspan['events']['cell'] = 3; 468 $table->data['events']['cell'] = $item['failed']; 469 } 470 else { 471 $table1 = new stdClass(); 472 $table1->width = '99%'; 473 474 $table1->align = array(); 475 $table1->align[0] = 'center'; 476 $table1->align[2] = 'center'; 477 478 $table1->data = array (); 479 480 $table1->head = array (); 481 $table1->head[0] = __('Status'); 482 $table1->head[1] = __('Name'); 483 $table1->head[2] = __('Type'); 484 $table1->head[3] = __('Agent'); 485 $table1->head[4] = __('Severity'); 486 $table1->head[5] = __('Val. by'); 487 $table1->head[6] = __('Timestamp'); 488 489 foreach ($item['data'] as $k => $event) { 490 //First pass along the class of this row 491 $table1->cellclass[$k][1] = $table1->cellclass[$k][3] = 492 $table1->cellclass[$k][4] = $table1->cellclass[$k][5] = 493 $table1->cellclass[$k][6] = 494 get_priority_class ($event["criticity"]); 495 496 $data = array (); 497 498 // Colored box 499 switch ($event['estado']) { 500 case 0: 501 $img_st = "images/star.png"; 502 $title_st = __('New event'); 503 break; 504 case 1: 505 $img_st = "images/tick.png"; 506 $title_st = __('Event validated'); 507 break; 508 case 2: 509 $img_st = "images/hourglass.png"; 510 $title_st = __('Event in process'); 511 break; 512 } 513 $data[] = html_print_image ($img_st, true, 514 array ("class" => "image_status", 515 "width" => 16, 516 "title" => $title_st, 517 "id" => 'status_img_' . $event["id_evento"])); 518 519 $data[] = ui_print_truncate_text( 520 io_safe_output($event['evento']), 521 140, false, true); 522 523 //$data[1] = $event['event_type']; 524 $data[] = events_print_type_img ($event["event_type"], true); 525 526 if (!empty($event['id_agente'])) 527 $data[] = agents_get_name($event['id_agente']); 528 else 529 $data[] = __('Pandora System'); 530 $data[] = get_priority_name ($event['criticity']); 531 if (empty($event['id_usuario']) && $event['estado'] == EVENT_VALIDATE) { 532 $data[] = '<i>' . __('System') . '</i>'; 533 } 534 else { 535 $user_name = db_get_value ('fullname', 'tusuario', 'id_user', $event['id_usuario']); 536 $data[] = io_safe_output($user_name); 537 } 538 $data[] = '<font style="font-size: 6pt;">' . 539 date($config['date_format'], $event['timestamp_rep']) . 540 '</font>'; 541 array_push ($table1->data, $data); 542 } 543 544 $table->colspan['events']['cell'] = 3; 545 $table->data['events']['cell'] = html_print_table($table1, true); 546 547 548 549 if (!empty($item['chart']['by_agent'])) { 550 $table1 = new stdClass(); 551 $table1->width = '99%'; 552 $table1->head = array (); 553 $table1->head[0] = __('Events by agent'); 554 $table1->data[0][0] = $item['chart']['by_agent']; 555 556 $table->colspan['chart_by_agent']['cell'] = 3; 557 $table->cellstyle['chart_by_agent']['cell'] = 'text-align: center;'; 558 $table->data['chart_by_agent']['cell'] = html_print_table($table1, true); 559 } 560 561 if (!empty($item['chart']['by_user_validator'])) { 562 $table1 = new stdClass(); 563 $table1->width = '99%'; 564 $table1->head = array (); 565 $table1->head[0] = __('Events by user validator'); 566 $table1->data[0][0] = $item['chart']['by_user_validator']; 567 568 $table->colspan['chart_by_user_validator']['cell'] = 3; 569 $table->cellstyle['chart_by_user_validator']['cell'] = 'text-align: center;'; 570 $table->data['chart_by_user_validator']['cell'] = html_print_table($table1, true); 571 } 572 573 if (!empty($item['chart']['by_criticity'])) { 574 $table1 = new stdClass(); 575 $table1->width = '99%'; 576 $table1->head = array (); 577 $table1->head[0] = __('Events by Severity'); 578 $table1->data[0][0] = $item['chart']['by_criticity']; 579 580 $table->colspan['chart_by_criticity']['cell'] = 3; 581 $table->cellstyle['chart_by_criticity']['cell'] = 'text-align: center;'; 582 $table->data['chart_by_criticity']['cell'] = html_print_table($table1, true); 583 } 584 585 if (!empty($item['chart']['validated_vs_unvalidated'])) { 586 $table1 = new stdClass(); 587 $table1->width = '99%'; 588 $table1->head = array (); 589 $table1->head[0] = __('Events validated vs unvalidated'); 590 $table1->data[0][0] = $item['chart']['validated_vs_unvalidated']; 591 592 $table->colspan['chart_validated_vs_unvalidated']['cell'] = 3; 593 $table->cellstyle['chart_validated_vs_unvalidated']['cell'] = 'text-align: center;'; 594 $table->data['chart_validated_vs_unvalidated']['cell'] = html_print_table($table1, true); 595 } 596 } 597} 598 599function reporting_html_event_report_module($table, $item) { 600 601 global $config; 602 603 if (!empty($item['failed'])) { 604 $table->colspan['events']['cell'] = 3; 605 $table->data['events']['cell'] = $item['failed']; 606 } 607 else { 608 $table1 = new stdClass(); 609 $table1->width = '99%'; 610 $table1->data = array (); 611 $table1->head = array (); 612 $table1->head[0] = __('Status'); 613 $table1->head[1] = __('Event name'); 614 $table1->head[2] = __('Event type'); 615 $table1->head[3] = __('Severity'); 616 $table1->head[4] = __('Count'); 617 $table1->head[5] = __('Timestamp'); 618 $table1->style[0] = 'text-align: center;'; 619 $table1->style[4] = 'text-align: center;'; 620 621 622 foreach ($item['data'] as $i => $event) { 623 $data = array(); 624 625 $table1->cellclass[$i][1] = 626 $table1->cellclass[$i][2] = 627 $table1->cellclass[$i][3] = 628 $table1->cellclass[$i][4] = 629 $table1->cellclass[$i][5] = get_priority_class($event["criticity"]); 630 631 // Colored box 632 switch ($event['estado']) { 633 case 0: 634 $img_st = "images/star.png"; 635 $title_st = __('New event'); 636 break; 637 case 1: 638 $img_st = "images/tick.png"; 639 $title_st = __('Event validated'); 640 break; 641 case 2: 642 $img_st = "images/hourglass.png"; 643 $title_st = __('Event in process'); 644 break; 645 } 646 647 $data[0] = html_print_image ($img_st, true, 648 array ("class" => "image_status", 649 "width" => 16, 650 "title" => $title_st, 651 "id" => 'status_img_' . $event["id_evento"])); 652 $data[1] = io_safe_output($event['evento']); 653 $data[2] = $event['event_type']; 654 $data[3] = get_priority_name ($event['criticity']); 655 $data[4] = $event['event_rep']; 656 $data[5] = date($config['date_format'], $event['timestamp_rep']); 657 658 $table1->data[] = $data; 659 } 660 661 $table->colspan['events']['cell'] = 3; 662 $table->data['events']['cell'] = html_print_table($table1, true); 663 } 664} 665 666function reporting_html_inventory_changes($table, $item) { 667 if (!empty($item['failed'])) { 668 $table->colspan['failed']['cell'] = 3; 669 $table->cellstyle['failed']['cell'] = 'text-align: center;'; 670 $table->data['failed']['cell'] = $item['failed']; 671 } 672 else { 673 foreach ($item['data'] as $module_item) { 674 $table1 = null; 675 $table1->width = '99%'; 676 677 $table1->cellstyle[0][0] = 678 $table1->cellstyle[0][1] = 679 'background: #373737; color: #FFF;'; 680 $table1->data[0][0] = $module_item['agent']; 681 $table1->data[0][1] = $module_item['module']; 682 683 684 $table1->cellstyle[1][0] = 685 'background: #373737; color: #FFF;'; 686 $table1->data[1][0] = $module_item['date']; 687 $table1->colspan[1][0] = 2; 688 689 690 $table1->cellstyle[2][0] = 691 'background: #373737; color: #FFF; text-align: center;'; 692 $table1->data[2][0] = __('Added'); 693 $table1->colspan[2][0] = 2; 694 695 if (count ($module_item['added'])) { 696 $table1->data = array_merge($table1->data, $module_item['added']); 697 } 698 699 700 $table1->cellstyle[3 + count($module_item['added'])][0] = 701 'background: #373737; color: #FFF; text-align: center;'; 702 $table1->data[3 + count($module_item['added'])][0] = __('Deleted'); 703 $table1->colspan[3 + count($module_item['added'])][0] = 2; 704 705 if (count ($module_item['deleted'])) { 706 $table1->data = array_merge($table1->data, $module_item['deleted']); 707 } 708 709 710 $table->colspan[ 711 $module_item['agent'] . "_" .$module_item['module']]['cell'] = 3; 712 $table->data[ 713 $module_item['agent'] . "_" .$module_item['module']]['cell'] = 714 html_print_table($table1, true); 715 } 716 } 717} 718 719function reporting_html_inventory($table, $item) { 720 if (!empty($item['failed'])) { 721 $table->colspan['failed']['cell'] = 3; 722 $table->cellstyle['failed']['cell'] = 'text-align: center;'; 723 $table->data['failed']['cell'] = $item['failed']; 724 } 725 else { 726 foreach ($item['data'] as $module_item) { 727 $table1 = null; 728 $table1->width = '99%'; 729 730 $first = reset($module_item['data']); 731 $count_columns = count($first); 732 733 734 $table1->cellstyle[0][0] = 735 'background: #373737; color: #FFF;'; 736 $table1->data[0][0] = $module_item['agent_name']; 737 if ($count_columns == 1) 738 $table1->colspan[0][0] = $count_columns + 1; // + columm date 739 else 740 $table1->colspan[0][0] = $count_columns; 741 742 743 $table1->cellstyle[1][0] = 744 $table1->cellstyle[1][1] = 745 'background: #373737; color: #FFF;'; 746 $table1->data[1][0] = $module_item['name']; 747 if ($count_columns - 1 > 0) 748 $table1->colspan[1][0] = $count_columns - 1; 749 $table1->data[1][1] = $module_item['timestamp']; 750 751 752 $table1->cellstyle[2] = array_pad( 753 array(), 754 $count_columns, 755 'background: #373737; color: #FFF;'); 756 $table1->data[2] = array_keys($first); 757 if ($count_columns - 1 == 0) { 758 $table1->colspan[2][0] = $count_columns + 1; // + columm date; 759 } 760 761 $table1->data = array_merge($table1->data, $module_item['data']); 762 763 764 $table->colspan[ 765 $module_item['name'] . "_" .$module_item['id_agente']]['cell'] = 3; 766 $table->data[ 767 $module_item['name'] . "_" .$module_item['id_agente']]['cell'] = 768 html_print_table($table1, true); 769 770 771 } 772 } 773 774} 775 776function reporting_html_agent_module($table, $item) { 777 $table->colspan['agent_module']['cell'] = 3; 778 $table->cellstyle['agent_module']['cell'] = 'text-align: center;'; 779 780 if (!empty($item['failed'])) { 781 $table->data['agent_module']['cell'] = $item['failed']; 782 } 783 else { 784 $table_data = '<table cellpadding="1" cellspacing="4" cellspacing="0" border="0" style="background-color: #EEE;">'; 785 786 $table_data .= "<th>" . __("Agents") . " / " . __("Modules") . "</th>"; 787 788 789 $first = reset($item['data']); 790 $list_modules = $first['modules']; 791 792 foreach ($list_modules as $module_name => $module) { 793 $file_name = string2image( 794 ui_print_truncate_text($module_name, 'module_small', 795 false, true, false, '...'), 796 false, false, 6, 270, '#B1B1B1', 'FFF', 4, 0); 797 $table_data .= '<th width="22px">' . 798 html_print_image($file_name, true, 799 array('title' => $module_name)) . 800 "</th>"; 801 } 802 803 804 805 foreach ($item['data'] as $row) { 806 $table_data .= "<tr style='height: 35px;'>"; 807 switch ($row['agent_status']) { 808 case AGENT_STATUS_ALERT_FIRED: 809 $rowcolor = COL_ALERTFIRED; 810 $textcolor = '#000'; 811 break; 812 case AGENT_STATUS_CRITICAL: 813 $rowcolor = COL_CRITICAL; 814 $textcolor = '#FFF'; 815 break; 816 case AGENT_STATUS_WARNING: 817 $rowcolor = COL_WARNING; 818 $textcolor = '#000'; 819 break; 820 case AGENT_STATUS_NORMAL: 821 $rowcolor = COL_NORMAL; 822 $textcolor = '#FFF'; 823 break; 824 case AGENT_STATUS_UNKNOWN: 825 case AGENT_STATUS_ALL: 826 default: 827 $rowcolor = COL_UNKNOWN; 828 $textcolor = '#FFF'; 829 break; 830 } 831 832 $file_name = string2image( 833 ui_print_truncate_text($row['agent_name'], 'agent_small', 834 false, true, false, '...'), 835 false, false, 6, 0, $rowcolor, $textcolor, 4, 0); 836 $table_data .= "<td style='background-color: " . $rowcolor . ";'>" . 837 html_print_image($file_name, true, 838 array('title' => $row['agent_name'])) . "</td>"; 839 840 foreach ($row['modules'] as $module_name => $module) { 841 if (is_null($module)) { 842 $table_data .= "<td style='background-color: #DDD;'></td>"; 843 } 844 else { 845 $table_data .= "<td style='text-align: center; background-color: #DDD;'>"; 846 switch ($module) { 847 case AGENT_STATUS_NORMAL: 848 $table_data .= ui_print_status_image( 849 'module_ok.png', 850 __("%s in %s : NORMAL", 851 $module_name, 852 $row['agent_name']), 853 true, array('width' => '20px', 'height' => '20px')); 854 break; 855 case AGENT_STATUS_CRITICAL: 856 $table_data .= ui_print_status_image( 857 'module_critical.png', 858 __("%s in %s : CRITICAL", 859 $module_name, 860 $row['agent_name']), 861 true, array('width' => '20px', 'height' => '20px')); 862 break; 863 case AGENT_STATUS_WARNING: 864 $table_data .= ui_print_status_image( 865 'module_warning.png', 866 __("%s in %s : WARNING", 867 $module_name, 868 $row['agent_name']), 869 true, array('width' => '20px', 'height' => '20px')); 870 break; 871 case AGENT_STATUS_UNKNOWN: 872 $table_data .= ui_print_status_image( 873 'module_unknown.png', 874 __("%s in %s : UNKNOWN", 875 $module_name, 876 $row['agent_name']), 877 true, array('width' => '20px', 'height' => '20px')); 878 break; 879 case AGENT_STATUS_ALERT_FIRED: 880 $table_data .= ui_print_status_image( 881 'module_alertsfired.png', 882 __("%s in %s : ALERTS FIRED", 883 $module_name, 884 $row['agent_name']), 885 true, array('width' => '20px', 'height' => '20px')); 886 break; 887 } 888 $table_data .= "</td>"; 889 } 890 891 } 892 } 893 894 $table_data .= "</table>"; 895 896 $table_data .= "<div class='legend_basic' style='width: 96%'>"; 897 898 $table_data .= "<table>"; 899 $table_data .= "<tr><td colspan='2' style='padding-bottom: 10px;'><b>" . __('Legend') . "</b></td></tr>"; 900 $table_data .= "<tr><td class='legend_square_simple'><div style='background-color: " . COL_ALERTFIRED . ";'></div></td><td>" . __("Orange cell when the module has fired alerts") . "</td></tr>"; 901 $table_data .= "<tr><td class='legend_square_simple'><div style='background-color: " . COL_CRITICAL . ";'></div></td><td>" . __("Red cell when the module has a critical status") . "</td></tr>"; 902 $table_data .= "<tr><td class='legend_square_simple'><div style='background-color: " . COL_WARNING . ";'></div></td><td>" . __("Yellow cell when the module has a warning status") . "</td></tr>"; 903 $table_data .= "<tr><td class='legend_square_simple'><div style='background-color: " . COL_NORMAL . ";'></div></td><td>" . __("Green cell when the module has a normal status") . "</td></tr>"; 904 $table_data .= "<tr><td class='legend_square_simple'><div style='background-color: " . COL_UNKNOWN . ";'></div></td><td>" . __("Grey cell when the module has an unknown status") . "</td></tr>"; 905 $table_data .= "</table>"; 906 $table_data .= "</div>"; 907 908 909 $table->data['agent_module']['cell'] = $table_data; 910 } 911} 912 913function reporting_html_exception($table, $item) { 914 915 if (!empty($item['failed'])) { 916 $table->colspan['group_report']['cell'] = 3; 917 $table->cellstyle['group_report']['cell'] = 'text-align: center;'; 918 $table->data['group_report']['cell'] = $item['failed']; 919 } 920 else { 921 $table1->width = '99%'; 922 923 $table1->align = array(); 924 $table1->align['agent'] = 'left'; 925 $table1->align['module'] = 'left'; 926 $table1->align['operation'] = 'left'; 927 $table1->align['value'] = 'right'; 928 929 $table1->data = array (); 930 931 $table1->headstyle = array(); 932 $table1->headstyle['agent'] = 'text-align: left'; 933 $table1->headstyle['module'] = 'text-align: left'; 934 $table1->headstyle['operation'] = 'text-align: left'; 935 $table1->headstyle['value'] = 'text-align: right'; 936 937 $table1->head = array (); 938 $table1->head['agent'] = __('Agent'); 939 $table1->head['module'] = __('Module'); 940 $table1->head['operation'] = __('Operation'); 941 $table1->head['value'] = __('Value'); 942 943 foreach ($item['data'] as $data) { 944 $row = array(); 945 $row['agent'] = $data['agent']; 946 $row['module'] = $data['module']; 947 $row['operation'] = $data['operation']; 948 $row['value'] = $data['formated_value']; 949 950 $table1->data[] = $row; 951 } 952 953 $table->colspan['data']['cell'] = 3; 954 $table->cellstyle['data']['cell'] = 'text-align: center;'; 955 $table->data['data']['cell'] = html_print_table($table1, true); 956 957 if (!empty($item['chart'])) { 958 $table->colspan['chart_pie']['cell'] = 3; 959 $table->cellstyle['chart_pie']['cell'] = 'text-align: center;'; 960 $table->data['chart_pie']['cell'] = $item["chart"]["pie"]; 961 962 $table->colspan['chart_hbar']['cell'] = 3; 963 $table->cellstyle['chart_hbar']['cell'] = 'text-align: center;'; 964 $table->data['chart_hbar']['cell'] = $item["chart"]["hbar"]; 965 } 966 967 if (!empty($item['resume'])) { 968 $table1 = null; 969 $table1->width = '99%'; 970 971 $table1->align = array(); 972 $table1->align['min'] = 'right'; 973 $table1->align['avg'] = 'right'; 974 $table1->align['max'] = 'right'; 975 976 $table1->headstyle = array(); 977 $table1->headstyle['min'] = 'text-align: right'; 978 $table1->headstyle['avg'] = 'text-align: right'; 979 $table1->headstyle['max'] = 'text-align: right'; 980 981 $table1->head = array (); 982 $table1->head['min'] = __('Min Value'); 983 $table1->head['avg'] = __('Average Value'); 984 $table1->head['max'] = __('Max Value'); 985 986 $table1->data = array (); 987 $table1->data[] = array( 988 'min' => $item['resume']['min']['formated_value'], 989 'avg' => $item['resume']['avg']['formated_value'], 990 'max' => $item['resume']['max']['formated_value']); 991 992 $table->colspan['resume']['cell'] = 3; 993 $table->cellstyle['resume']['cell'] = 'text-align: center;'; 994 $table->data['resume']['cell'] = html_print_table($table1, true); 995 } 996 } 997} 998 999function reporting_html_group_report($table, $item) { 1000 global $config; 1001 1002 1003 $table->colspan['group_report']['cell'] = 3; 1004 $table->cellstyle['group_report']['cell'] = 'text-align: center;'; 1005 $table->data['group_report']['cell'] = "<table width='100%'> 1006 <tr> 1007 <td></td> 1008 <td colspan='3'><div class='cellBold cellCenter'>" . 1009 __('Total') . "</div></td> 1010 <td colspan='3'><div class='cellBold cellCenter'>" . 1011 __('Unknown') . "</div></td> 1012 </tr> 1013 <tr> 1014 <td><div class='cellBold cellCenter'>" . 1015 __('Agents') . "</div></td> 1016 <td colspan='3'><div class='cellBold cellCenter cellWhite cellBorder1 cellBig'>" . 1017 $item["data"]['group_stats']['total_agents'] . "</div></td> 1018 <td colspan='3'><div class='cellBold cellCenter cellUnknown cellBorder1 cellBig'>" . 1019 $item["data"]['group_stats']['agents_unknown'] . "</div></td> 1020 </tr> 1021 <tr> 1022 <td></td> 1023 <td><div class='cellBold cellCenter'>" . 1024 __('Total') . "</div></td> 1025 <td><div class='cellBold cellCenter'>" . 1026 __('Normal') . "</div></td> 1027 <td><div class='cellBold cellCenter'>" . 1028 __('Critical') . "</div></td> 1029 <td><div class='cellBold cellCenter'>" . 1030 __('Warning') . "</div></td> 1031 <td><div class='cellBold cellCenter'>" . 1032 __('Unknown') . "</div></td> 1033 <td><div class='cellBold cellCenter'>" . 1034 __('Not init') . "</div></td> 1035 </tr> 1036 <tr> 1037 <td><div class='cellBold cellCenter'>" . 1038 __('Monitors') . "</div></td> 1039 <td><div class='cellBold cellCenter cellWhite cellBorder1 cellBig'>" . 1040 $item["data"]['group_stats']['monitor_checks'] . "</div></td> 1041 <td><div class='cellBold cellCenter cellNormal cellBorder1 cellBig'>" . 1042 $item["data"]['group_stats']['monitor_ok'] ."</div></td> 1043 <td><div class='cellBold cellCenter cellCritical cellBorder1 cellBig'>" . 1044 $item["data"]['group_stats']['monitor_critical'] . "</div></td> 1045 <td><div class='cellBold cellCenter cellWarning cellBorder1 cellBig'>" . 1046 $item["data"]['group_stats']['monitor_warning'] . "</div></td> 1047 <td><div class='cellBold cellCenter cellUnknown cellBorder1 cellBig'>" . 1048 $item["data"]['group_stats']['monitor_unknown'] . "</div></td> 1049 <td><div class='cellBold cellCenter cellNotInit cellBorder1 cellBig'>" . 1050 $item["data"]['group_stats']['monitor_not_init'] . "</div></td> 1051 </tr> 1052 <tr> 1053 <td></td> 1054 <td colspan='3'><div class='cellBold cellCenter'>" . 1055 __('Defined') . "</div></td> 1056 <td colspan='3'><div class='cellBold cellCenter'>" . 1057 __('Fired') . "</div></td> 1058 </tr> 1059 <tr> 1060 <td><div class='cellBold cellCenter'>" . 1061 __('Alerts') . "</div></td> 1062 <td colspan='3'><div class='cellBold cellCenter cellWhite cellBorder1 cellBig'>" . 1063 $item["data"]['group_stats']['monitor_alerts'] . "</div></td> 1064 <td colspan='3'><div class='cellBold cellCenter cellAlert cellBorder1 cellBig'>" . 1065 $item["data"]['group_stats']['monitor_alerts_fired'] . "</div></td> 1066 </tr> 1067 <tr> 1068 <td></td> 1069 <td colspan='6'><div class='cellBold cellCenter'>" . 1070 __('Last %s', human_time_description_raw($item['date']['period'])) . "</div></td> 1071 </tr> 1072 <tr> 1073 <td><div class='cellBold cellCenter'>" . 1074 __('Events') . "</div></td> 1075 <td colspan='6'><div class='cellBold cellCenter cellWhite cellBorder1 cellBig'>" . 1076 $item["data"]["count_events"] . "</div></td> 1077 </tr> 1078 </table>"; 1079} 1080 1081function reporting_html_event_report_agent($table, $item) { 1082 global $config; 1083 1084 $table1 = new stdClass(); 1085 $table1->width = '99%'; 1086 1087 $table1->align = array(); 1088 $table1->align[0] = 'center'; 1089 $table1->align[1] = 'center'; 1090 $table1->align[3] = 'center'; 1091 1092 $table1->data = array (); 1093 1094 $table1->head = array (); 1095 $table1->head[0] = __('Status'); 1096 $table1->head[1] = __('Count'); 1097 $table1->head[2] = __('Name'); 1098 $table1->head[3] = __('Type'); 1099 $table1->head[4] = __('Severity'); 1100 $table1->head[5] = __('Val. by'); 1101 $table1->head[6] = __('Timestamp'); 1102 1103 foreach ($item['data'] as $i => $event) { 1104 $table1->cellclass[$i][1] = 1105 $table1->cellclass[$i][2] = 1106 $table1->cellclass[$i][4] = 1107 $table1->cellclass[$i][5] = 1108 $table1->cellclass[$i][6] = 1109 get_priority_class ($event["criticity"]); 1110 1111 $data = array (); 1112 // Colored box 1113 switch ($event['status']) { 1114 case 0: 1115 $img_st = "images/star.png"; 1116 $title_st = __('New event'); 1117 break; 1118 case 1: 1119 $img_st = "images/tick.png"; 1120 $title_st = __('Event validated'); 1121 break; 1122 case 2: 1123 $img_st = "images/hourglass.png"; 1124 $title_st = __('Event in process'); 1125 break; 1126 } 1127 $data[] = html_print_image ($img_st, true, 1128 array ("class" => "image_status", 1129 "width" => 16, 1130 "title" => $title_st)); 1131 1132 $data[] = $event['count']; 1133 1134 $data[] = ui_print_truncate_text( 1135 io_safe_output($event['name']), 1136 140, false, true); 1137 //$data[] = $event['event_type']; 1138 $data[] = events_print_type_img ($event["type"], true); 1139 1140 $data[] = get_priority_name ($event['criticity']); 1141 if (empty($event['validated_by']) && $event['status'] == EVENT_VALIDATE) { 1142 $data[] = '<i>' . __('System') . '</i>'; 1143 } 1144 else { 1145 $user_name = db_get_value ('fullname', 'tusuario', 'id_user', $event['validated_by']); 1146 $data[] = io_safe_output($user_name); 1147 } 1148 $data[] = '<font style="font-size: 6pt;">' . 1149 date($config['date_format'], $event['timestamp']) . '</font>'; 1150 array_push ($table1->data, $data); 1151 } 1152 1153 $table->colspan['event_list']['cell'] = 3; 1154 $table->cellstyle['event_list']['cell'] = 'text-align: center;'; 1155 $table->data['event_list']['cell'] = html_print_table($table1, true); 1156 1157 if (!empty($item['chart']['by_user_validator'])) { 1158 $table1 = new stdClass(); 1159 $table1->width = '99%'; 1160 $table1->head = array (); 1161 $table1->head[0] = __('Events validated by user'); 1162 $table1->data[0][0] = $item['chart']['by_user_validator']; 1163 1164 $table->colspan['chart_by_user_validator']['cell'] = 3; 1165 $table->cellstyle['chart_by_user_validator']['cell'] = 'text-align: center;'; 1166 $table->data['chart_by_user_validator']['cell'] = html_print_table($table1, true); 1167 } 1168 1169 if (!empty($item['chart']['by_criticity'])) { 1170 $table1 = new stdClass(); 1171 $table1->width = '99%'; 1172 $table1->head = array (); 1173 $table1->head[0] = __('Events by severity'); 1174 $table1->data[0][0] = $item['chart']['by_criticity']; 1175 1176 $table->colspan['chart_by_criticity']['cell'] = 3; 1177 $table->cellstyle['chart_by_criticity']['cell'] = 'text-align: center;'; 1178 $table->data['chart_by_criticity']['cell'] = html_print_table($table1, true); 1179 } 1180 1181 if (!empty($item['chart']['validated_vs_unvalidated'])) { 1182 $table1 = new stdClass(); 1183 $table1->width = '99%'; 1184 $table1->head = array (); 1185 $table1->head[0] = __('Amount events validated'); 1186 $table1->data[0][0] = $item['chart']['validated_vs_unvalidated']; 1187 1188 $table->colspan['chart_validated_vs_unvalidated']['cell'] = 3; 1189 $table->cellstyle['chart_validated_vs_unvalidated']['cell'] = 'text-align: center;'; 1190 $table->data['chart_validated_vs_unvalidated']['cell'] = html_print_table($table1, true); 1191 } 1192} 1193 1194function reporting_html_historical_data($table, $item) { 1195 $table1->width = '100%'; 1196 $table1->head = array (__('Date'), __('Data')); 1197 1198 $table1->data = array (); 1199 foreach ($item['data'] as $data) { 1200 $row = array($data[__('Date')], $data[__('Data')]); 1201 $table1->data[] = $row; 1202 } 1203 1204 $table->colspan['database_serialized']['cell'] = 3; 1205 $table->cellstyle['database_serialized']['cell'] = 'text-align: center;'; 1206 $table->data['database_serialized']['cell'] = html_print_table($table1, true); 1207} 1208 1209function reporting_html_database_serialized($table, $item) { 1210 1211 $table1->width = '100%'; 1212 $table1->head = array (__('Date')); 1213 if (!empty($item['keys'])) { 1214 $table1->head = array_merge($table1->head, $item['keys']); 1215 } 1216 $table1->style[0] = 'text-align: left'; 1217 1218 $table1->data = array (); 1219 foreach ($item['data'] as $data) { 1220 foreach ($data['data'] as $data_unserialied) { 1221 $row = array($data['date']); 1222 $row = array_merge($row, $data_unserialied); 1223 $table1->data[] = $row; 1224 } 1225 } 1226 1227 $table->colspan['database_serialized']['cell'] = 3; 1228 $table->cellstyle['database_serialized']['cell'] = 'text-align: center;'; 1229 $table->data['database_serialized']['cell'] = html_print_table($table1, true); 1230} 1231 1232function reporting_html_group_configuration($table, $item) { 1233 1234 $table1 = new stdClass(); 1235 $table1->width = '100%'; 1236 $table1->head = array (); 1237 $table1->data = array (); 1238 $cell = ""; 1239 foreach ($item['data'] as $agent) { 1240 $table2 = new stdClass(); 1241 $table2->width = '100%'; 1242 $table2->data = array (); 1243 reporting_html_agent_configuration($table2, array('data' => $agent)); 1244 1245 $cell .= html_print_table($table2, true); 1246 } 1247 1248 $table->colspan['group_configuration']['cell'] = 3; 1249 $table->cellstyle['group_configuration']['cell'] = 'text-align: center;'; 1250 $table->data['group_configuration']['cell'] = $cell; 1251} 1252 1253function reporting_html_network_interfaces_report($table, $item) { 1254 1255 if (!empty($item['failed'])) { 1256 $table->colspan['interfaces']['cell'] = 3; 1257 $table->cellstyle['interfaces']['cell'] = 'text-align: left;'; 1258 $table->data['interfaces']['cell'] = $item['failed']; 1259 } 1260 else { 1261 1262 foreach ($item['data'] as $agent) { 1263 $table_agent = new StdCLass(); 1264 $table_agent->width = '100%'; 1265 $table_agent->data = array(); 1266 $table_agent->head = array(); 1267 $table_agent->head[0] = sprintf(__("Agent '%s'"), $agent['name']); 1268 $table_agent->headstyle = array(); 1269 $table_agent->headstyle[0] = 'font-size: 16px;'; 1270 $table_agent->style[0] = 'text-align: center'; 1271 1272 $table_agent->data['interfaces'] = ""; 1273 1274 foreach ($agent['interfaces'] as $interface) { 1275 $table_interface = new StdClass(); 1276 $table_interface->width = '100%'; 1277 $table_interface->data = array(); 1278 $table_interface->rowstyle = array(); 1279 $table_interface->head = array(); 1280 $table_interface->cellstyle = array(); 1281 $table_interface->title = sprintf(__("Interface '%s' throughput graph"), 1282 $interface['name']); 1283 $table_interface->head['ip'] = __('IP'); 1284 $table_interface->head['mac'] = __('Mac'); 1285 $table_interface->head['status'] = __('Actual status'); 1286 $table_interface->style['ip'] = 'text-align: left'; 1287 $table_interface->style['mac'] = 'text-align: left'; 1288 $table_interface->style['status'] = 'width: 150px; text-align: center'; 1289 1290 $data = array(); 1291 $data['ip'] = !empty($interface['ip']) ? $interface['ip'] : "--"; 1292 $data['mac'] = !empty($interface['mac']) ? $interface['mac'] : "--"; 1293 $data['status'] = $interface['status_image']; 1294 $table_interface->data['data'] = $data; 1295 1296 if (!empty($interface['chart'])) { 1297 $table_interface->data['graph'] = $interface['chart']; 1298 $table_interface->colspan['graph'][0] = 3; 1299 $table_interface->cellstyle['graph'][0] = 'text-align: center;'; 1300 } 1301 1302 $table_agent->data['interfaces'] .= html_print_table($table_interface, true); 1303 $table_agent->colspan[$interface_name][0] = 3; 1304 } 1305 1306 $id = uniq_id(); 1307 1308 $table->data['agents'][$id] = html_print_table($table_agent, true); 1309 $table->colspan[$id][0] = 3; 1310 } 1311 } 1312} 1313 1314function reporting_html_alert_report_group($table, $item) { 1315 $table->colspan['alerts']['cell'] = 3; 1316 $table->cellstyle['alerts']['cell'] = 'text-align: left;'; 1317 1318 $table1->width = '99%'; 1319 $table1->head = array (); 1320 $table1->head['agent'] = __('Agent'); 1321 $table1->head['module'] = __('Module'); 1322 $table1->head['template'] = __('Template'); 1323 $table1->head['actions'] = __('Actions'); 1324 $table1->head['fired'] = __('Fired'); 1325 $table1->data = array (); 1326 foreach ($item['data'] as $alert) { 1327 $row = array(); 1328 1329 $row['agent'] = $alert['agent']; 1330 $row['module'] = $alert['module']; 1331 $row['template'] = $alert['template']; 1332 $row['actions'] = $alert['template']; 1333 1334 $row['actions'] = '<ul class="action_list">' . "\n"; 1335 foreach ($alert['action'] as $action) { 1336 $row['actions'] .= '<li>' . $action . '</li>' . "\n"; 1337 } 1338 $row['actions'] .= '</ul>'; 1339 1340 $row['fired'] = '<ul style="list-style-type: disc; margin-left: 10px;">' . "\n"; 1341 foreach ($alert['fired'] as $fired) { 1342 $row['fired'] .= '<li>' . $fired . '</li>' . "\n"; 1343 } 1344 $row['fired'] .= '</ul>'; 1345 1346 $table1->data[] = $row; 1347 } 1348 1349 $table->data['alerts']['cell'] = html_print_table($table1, true); 1350} 1351 1352function reporting_html_alert_report_agent($table, $item) { 1353 $table->colspan['alerts']['cell'] = 3; 1354 $table->cellstyle['alerts']['cell'] = 'text-align: left;'; 1355 1356 $table1 = new stdClass(); 1357 $table1->width = '99%'; 1358 $table1->head = array (); 1359 $table1->head['module'] = __('Module'); 1360 $table1->head['template'] = __('Template'); 1361 $table1->head['actions'] = __('Actions'); 1362 $table1->head['fired'] = __('Fired'); 1363 $table1->data = array (); 1364 foreach ($item['data'] as $alert) { 1365 $row = array(); 1366 1367 $row['module'] = $alert['module']; 1368 $row['template'] = $alert['template']; 1369 $row['actions'] = $alert['template']; 1370 1371 $row['actions'] = '<ul class="action_list">' . "\n"; 1372 foreach ($alert['action'] as $action) { 1373 $row['actions'] .= '<li>' . $action . '</li>' . "\n"; 1374 } 1375 $row['actions'] .= '</ul>'; 1376 1377 $row['fired'] = '<ul style="list-style-type: disc; margin-left: 10px;">' . "\n"; 1378 foreach ($alert['fired'] as $fired) { 1379 $row['fired'] .= '<li>' . $fired . '</li>' . "\n"; 1380 } 1381 $row['fired'] .= '</ul>'; 1382 1383 $table1->data[] = $row; 1384 } 1385 1386 $table->data['alerts']['cell'] = html_print_table($table1, true); 1387} 1388 1389function reporting_html_alert_report_module($table, $item) { 1390 $table->colspan['alerts']['cell'] = 3; 1391 $table->cellstyle['alerts']['cell'] = 'text-align: left;'; 1392 1393 $table1 = new stdClass(); 1394 $table1->width = '99%'; 1395 $table1->head = array (); 1396 $table1->head['template'] = __('Template'); 1397 $table1->head['actions'] = __('Actions'); 1398 $table1->head['fired'] = __('Fired'); 1399 $table1->data = array (); 1400 foreach ($item['data'] as $alert) { 1401 $row = array(); 1402 1403 $row['template'] = $alert['template']; 1404 $row['actions'] = $alert['template']; 1405 1406 $row['actions'] = '<ul class="action_list">' . "\n"; 1407 foreach ($alert['action'] as $action) { 1408 $row['actions'] .= '<li>' . $action . '</li>' . "\n"; 1409 } 1410 $row['actions'] .= '</ul>'; 1411 1412 $row['fired'] = '<ul style="list-style-type: disc; margin-left: 10px;">' . "\n"; 1413 foreach ($alert['fired'] as $fired) { 1414 $row['fired'] .= '<li>' . $fired . '</li>' . "\n"; 1415 } 1416 $row['fired'] .= '</ul>'; 1417 1418 $table1->data[] = $row; 1419 } 1420 1421 $table->data['alerts']['cell'] = html_print_table($table1, true); 1422} 1423 1424function reporting_html_sql_graph($table, $item) { 1425 $table->colspan['chart']['cell'] = 3; 1426 $table->cellstyle['chart']['cell'] = 'text-align: center;'; 1427 $table->data['chart']['cell'] = $item['chart']; 1428} 1429 1430function reporting_html_monitor_report($table, $item, $mini) { 1431 if ($mini) { 1432 $font_size = '1.5'; 1433 } 1434 else { 1435 $font_size = '3'; 1436 } 1437 1438 $table->colspan['module']['cell'] = 3; 1439 $table->cellstyle['module']['cell'] = 'text-align: center;'; 1440 1441 $table1 = new stdClass(); 1442 $table1->width = '99%'; 1443 $table1->head = array (); 1444 $table1->data = array (); 1445 if ($item['data']['unknown'] == 1) { 1446 $table1->data['data']['unknown'] = 1447 '<p style="font: bold ' . $font_size . 'em Arial, Sans-serif; color: ' . COL_UNKNOWN . ';">'; 1448 $table1->data['data']['unknown'] .= __('Unknown') . "</p>"; 1449 } 1450 else { 1451 $table1->data['data']['ok'] = 1452 '<p style="font: bold ' . $font_size . 'em Arial, Sans-serif; color: ' . COL_NORMAL . ';">'; 1453 $table1->data['data']['ok'] .= 1454 html_print_image("images/module_ok.png", true) . ' ' . 1455 __('OK') . ': ' . $item['data']["ok"]["formated_value"].' %</p>'; 1456 1457 $table1->data['data']['fail'] = 1458 '<p style="font: bold ' . $font_size . 'em Arial, Sans-serif; color: ' . COL_CRITICAL . ';">'; 1459 $table1->data['data']['fail'] .= 1460 html_print_image("images/module_critical.png", true) . ' ' . 1461 __('Not OK') . ': ' . $item['data']["fail"]["formated_value"] . ' % ' . '</p>'; 1462 } 1463 1464 $table->data['module']['cell'] = html_print_table($table1, true); 1465} 1466 1467function reporting_html_graph($table, $item) { 1468 $table->colspan['chart']['cell'] = 3; 1469 $table->cellstyle['chart']['cell'] = 'text-align: center;'; 1470 $table->data['chart']['cell'] = $item['chart']; 1471} 1472 1473function reporting_html_prediction_date($table, $item, $mini) { 1474 reporting_html_value($table, $item, $mini, true); 1475} 1476 1477function reporting_html_agent_configuration(&$table, $item) { 1478 $table->colspan['agent']['cell'] = 3; 1479 $table->cellstyle['agent']['cell'] = 'text-align: left;'; 1480 1481 $table1 = new stdClass(); 1482 $table1->width = '99%'; 1483 $table1->head = array (); 1484 $table1->head['name'] = __('Agent name'); 1485 $table1->head['group'] = __('Group'); 1486 $table1->head['os'] = __('OS'); 1487 $table1->head['address'] = __('IP'); 1488 $table1->head['description'] = __('Description'); 1489 $table1->head['status'] = __('Status'); 1490 $table1->data = array (); 1491 $row = array(); 1492 $row['name'] = $item['data']['name']; 1493 $row['group'] = $item['data']['group_icon']; 1494 $row['address'] = $item['data']['os_icon']; 1495 $row['os'] = $item['data']['address']; 1496 $row['description'] = $item['data']['description']; 1497 if ($item['data']['enabled']) { 1498 $row['status'] = __('Enabled'); 1499 } 1500 else { 1501 $row['status'] = __('Disabled'); 1502 } 1503 $table1->data[] = $row; 1504 $table->data['agent']['cell'] = html_print_table($table1, true); 1505 1506 1507 $table->colspan['modules']['cell'] = 3; 1508 $table->cellstyle['modules']['cell'] = 'text-align: left;'; 1509 1510 if (empty($item['data']['modules'])) { 1511 $table->data['modules']['cell'] = __('Empty modules'); 1512 } 1513 else { 1514 $table1->width = '99%'; 1515 $table1->head = array (); 1516 $table1->head['name'] = __('Name'); 1517 $table1->head['type'] = __('Type'); 1518 $table1->head['warning_critical'] = __('Warning<br/>Critical'); 1519 $table1->head['threshold'] = __('Threshold'); 1520 $table1->head['group_icon'] = __('Group'); 1521 $table1->head['description'] = __('Description'); 1522 $table1->head['interval'] = __('Interval'); 1523 $table1->head['unit'] = __('Unit'); 1524 $table1->head['status'] = __('Status'); 1525 $table1->head['tags'] = __('Tags'); 1526 $table1->align = array(); 1527 $table1->align['name'] = 'left'; 1528 $table1->align['type'] = 'center'; 1529 $table1->align['warning_critical'] = 'right'; 1530 $table1->align['threshold'] = 'right'; 1531 $table1->align['group_icon'] = 'center'; 1532 $table1->align['description'] = 'left'; 1533 $table1->align['interval'] = 'right'; 1534 $table1->align['unit'] = 'left'; 1535 $table1->align['status'] = 'center'; 1536 $table1->align['tags'] = 'left'; 1537 $table1->data = array (); 1538 1539 foreach ($item['data']['modules'] as $module) { 1540 $row = array(); 1541 1542 $row['name'] = $module['name']; 1543 $row['type'] = $module['type_icon']; 1544 $row['warning_critical'] = 1545 $module['max_warning'] . " / " . $module['min_warning'] . 1546 "<br>" . 1547 $module['max_critical'] . " / " . $module['min_critical']; 1548 $row['threshold'] = $module['threshold']; 1549 $row['group_icon'] = ui_print_group_icon($item['data']['group'], true); 1550 $row['description'] = $module['description']; 1551 $row['interval'] = $module['interval']; 1552 $row['unit'] = $module['unit']; 1553 $row['status'] = $module['status_icon']; 1554 $row['tags'] = implode(",", $module['tags']); 1555 1556 $table1->data[] = $row; 1557 } 1558 1559 $table->data['modules']['cell'] = html_print_table($table1, true); 1560 } 1561} 1562 1563function reporting_html_TTRT_value(&$table, $item, $mini, $only_value = false, $check_empty = false) { 1564 reporting_html_value($table, $item, $mini, $only_value, $check_empty); 1565} 1566 1567function reporting_html_TTO_value(&$table, $item, $mini, $only_value = false, $check_empty = false) { 1568 reporting_html_value($table, $item, $mini, $only_value, $check_empty); 1569} 1570 1571function reporting_html_MTBF_value(&$table, $item, $mini, $only_value = false, $check_empty = false) { 1572 reporting_html_value($table, $item, $mini, $only_value, $check_empty); 1573} 1574 1575function reporting_html_MTTR_value(&$table, $item, $mini, $only_value = false, $check_empty = false) { 1576 reporting_html_value($table, $item, $mini, $only_value, $check_empty); 1577} 1578 1579function reporting_html_sum_value(&$table, $item, $mini) { 1580 reporting_html_value($table, $item, $mini); 1581} 1582 1583function reporting_html_avg_value(&$table, $item, $mini) { 1584 reporting_html_value($table, $item, $mini); 1585} 1586 1587function reporting_html_max_value(&$table, $item, $mini) { 1588 reporting_html_value($table, $item, $mini); 1589} 1590 1591function reporting_html_min_value(&$table, $item, $mini) { 1592 reporting_html_value($table, $item, $mini); 1593} 1594 1595function reporting_html_value(&$table, $item, $mini, $only_value = false, $check_empty = false) { 1596 if ($mini) { 1597 $font_size = '1.5'; 1598 } 1599 else { 1600 $font_size = '3'; 1601 } 1602 1603 $table->colspan['data']['cell'] = 3; 1604 $table->cellstyle['data']['cell'] = 'text-align: left;'; 1605 1606 1607 $table->data['data']['cell'] = '<p style="font: bold ' . $font_size . 'em Arial, Sans-serif; color: #000000;">'; 1608 1609 if ($check_empty && empty($item['data']['value'])) { 1610 $table->data['data']['cell'] .= __('Unknown'); 1611 } 1612 elseif ($only_value) { 1613 $table->data['data']['cell'] .= $item['data']['value']; 1614 } 1615 else { 1616 $table->data['data']['cell'] .= $item['data']['formated_value']; 1617 } 1618 1619 $table->data['data']['cell'] .= '</p>'; 1620} 1621 1622function reporting_html_url(&$table, $item, $key) { 1623 $table->colspan['data']['cell'] = 3; 1624 $table->cellstyle['data']['cell'] = 'text-align: left;'; 1625 $table->data['data']['cell'] = ' 1626 <iframe id="item_' . $key . '" src ="' . $item["url"] . '" width="100%" height="100%"> 1627 </iframe>'; 1628 // TODO: make this dynamic and get the height if the iframe to resize this item 1629 $table->data['data']['cell'] .= ' 1630 <script type="text/javascript"> 1631 $(document).ready (function () { 1632 $("#item_' . $key . '").height(500); 1633 }); 1634 </script>'; 1635} 1636 1637function reporting_html_text(&$table, $item) { 1638 $table->colspan['data']['cell'] = 3; 1639 $table->cellstyle['data']['cell'] = 'text-align: left;'; 1640 $table->data['data']['cell'] = $item['data']; 1641} 1642 1643function reporting_html_availability(&$table, $item) { 1644 1645 if (!empty($item["data"])) { 1646 $table1 = new stdClass(); 1647 $table1->width = '99%'; 1648 $table1->data = array (); 1649 1650 $table1->head = array (); 1651 $table1->head[0] = __('Agent'); 1652 // HACK it is saved in show_graph field. 1653 // Show interfaces instead the modules 1654 if ($item['kind_availability'] == 'address') { 1655 $table1->head[1] = __('IP Address'); 1656 } 1657 else { 1658 $table1->head[1] = __('Module'); 1659 } 1660 $table1->head[2] = __('# Checks'); 1661 $table1->head[3] = __('# Failed'); 1662 $table1->head[4] = __('% Fail'); 1663 $table1->head[5] = __('Time available'); 1664 $table1->head[6] = __('Time unavailable'); 1665 $table1->head[7] = __('% Ok'); 1666 1667 $table1->headstyle = array(); 1668 $table1->headstyle[2] = 'text-align: right'; 1669 $table1->headstyle[3] = 'text-align: right'; 1670 $table1->headstyle[4] = 'text-align: right'; 1671 $table1->headstyle[5] = 'text-align: right'; 1672 $table1->headstyle[6] = 'text-align: right'; 1673 $table1->headstyle[7] = 'text-align: right'; 1674 1675 $table1->style[0] = 'text-align: left'; 1676 $table1->style[1] = 'text-align: left'; 1677 $table1->style[2] = 'text-align: right'; 1678 $table1->style[3] = 'text-align: right'; 1679 $table1->style[4] = 'text-align: right'; 1680 $table1->style[5] = 'text-align: right'; 1681 $table1->style[6] = 'text-align: right'; 1682 $table1->style[7] = 'text-align: right'; 1683 1684 foreach ($item['data'] as $row) { 1685 $table_row = array(); 1686 $table_row[] = $row['agent']; 1687 $table_row[] = $row['availability_item']; 1688 $table_row[] = $row['checks']; 1689 $table_row[] = $row['failed']; 1690 $table_row[] = $row['fail']; 1691 $table_row[] = $row['poling_time']; 1692 $table_row[] = $row['time_unavaliable']; 1693 $table_row[] = $row['ok']; 1694 1695 $table1->data[] = $table_row; 1696 } 1697 } 1698 else { 1699 $table->colspan['error']['cell'] = 3; 1700 $table->data['error']['cell'] = 1701 __('There are no Agent/Modules defined'); 1702 } 1703 1704 $table->colspan[1][0] = 3; 1705 $data = array(); 1706 $data[0] = html_print_table($table1, true); 1707 array_push ($table->data, $data); 1708 1709 if ($item['resume'] && !empty($item["data"])) { 1710 $table1->width = '99%'; 1711 $table1->data = array (); 1712 1713 1714 1715 $table1->head = array (); 1716 $table1->head['min_text'] = __('Agent max'); 1717 $table1->head['min'] = __('Min Value'); 1718 $table1->head['avg'] = __('Average Value'); 1719 $table1->head['max_text'] = __('Agent min'); 1720 $table1->head['max'] = __('Max Value'); 1721 1722 $table1->headstyle = array(); 1723 $table1->headstyle['min_text'] = 'text-align: left'; 1724 $table1->headstyle['min'] = 'text-align: right'; 1725 $table1->headstyle['avg'] = 'text-align: right'; 1726 $table1->headstyle['max_text'] = 'text-align: left'; 1727 $table1->headstyle['max'] = 'text-align: right'; 1728 1729 1730 $table1->style = array(); 1731 $table1->style['min_text'] = 'text-align: left'; 1732 $table1->style['min'] = 'text-align: right'; 1733 $table1->style['avg'] = 'text-align: right'; 1734 $table1->style['max_text'] = 'text-align: left'; 1735 $table1->style['max'] = 'text-align: right'; 1736 1737 $table1->data[] = array( 1738 'min_text' => $item['resume']['min_text'], 1739 'min' => format_numeric($item['resume']['min'], 2) . "%", 1740 'avg' => format_numeric($item['resume']['avg'], 2) . "%", 1741 'max_text' => $item['resume']['max_text'], 1742 'max' => format_numeric($item['resume']['max'], 2) . "%" 1743 ); 1744 1745 $table->colspan[2][0] = 3; 1746 $data = array(); 1747 $data[0] = html_print_table($table1, true); 1748 array_push ($table->data, $data); 1749 } 1750} 1751 1752function reporting_html_general(&$table, $item) { 1753 1754 if (!empty($item["data"])) { 1755 switch ($item['subtype']) { 1756 case REPORT_GENERAL_NOT_GROUP_BY_AGENT: 1757 $table1 = new stdClass(); 1758 $table1->width = '99%'; 1759 $table1->data = array (); 1760 $table1->head = array (); 1761 $table1->head[0] = __('Agent'); 1762 $table1->head[1] = __('Module'); 1763 if ($item['date']['period'] != 0) { 1764 $table1->head[2] = __('Operation'); 1765 } 1766 $table1->head[3] = __('Value'); 1767 $table1->style[0] = 'text-align: left'; 1768 $table1->style[1] = 'text-align: left'; 1769 $table1->style[2] = 'text-align: left'; 1770 $table1->style[3] = 'text-align: left'; 1771 1772 foreach ($item['data'] as $row) { 1773 if ($item['date']['period'] != 0) { 1774 $table1->data[] = array( 1775 $row['agent'], 1776 $row['module'], 1777 $row['operator'], 1778 $row['formated_value']); 1779 } 1780 else { 1781 $table1->data[] = array( 1782 $row['agent'], 1783 $row['module'], 1784 $row['formated_value']); 1785 } 1786 } 1787 break; 1788 case REPORT_GENERAL_GROUP_BY_AGENT: 1789 $list_modules = array(); 1790 foreach ($item['data'] as $modules) { 1791 foreach ($modules as $name => $value) { 1792 $list_modules[$name] = null; 1793 } 1794 } 1795 $list_modules = array_keys($list_modules); 1796 1797 $table1->width = '99%'; 1798 $table1->data = array (); 1799 $table1->head = array_merge(array(__('Agent')), $list_modules); 1800 foreach ($item['data'] as $agent => $modules) { 1801 $row = array(); 1802 1803 $row['agent'] = $agent; 1804 $table1->style['agent'] = 'text-align: left;'; 1805 foreach ($list_modules as $name) { 1806 $table1->style[$name] = 'text-align: right;'; 1807 if (isset($modules[$name])) { 1808 $row[$name] = $modules[$name]; 1809 } 1810 else { 1811 $row[$name] = "--"; 1812 } 1813 } 1814 $table1->data[] = $row; 1815 } 1816 break; 1817 } 1818 1819 $table->colspan['data']['cell'] = 3; 1820 $table->cellstyle['data']['cell'] = 'text-align: center;'; 1821 $table->data['data']['cell'] = html_print_table($table1, true); 1822 } 1823 else { 1824 $table->colspan['error']['cell'] = 3; 1825 $table->data['error']['cell'] = 1826 __('There are no Agent/Modules defined'); 1827 } 1828 1829 if ($item['resume'] && !empty($item["data"])) { 1830 $table_summary = new stdClass(); 1831 $table_summary->width = '99%'; 1832 1833 $table_summary->data = array (); 1834 $table_summary->head = array (); 1835 $table_summary->head_colspan = array (); 1836 $table_summary->align = array(); 1837 1838 $table_summary->align[0] = 'left'; 1839 $table_summary->align[1] = 'right'; 1840 $table_summary->align[2] = 'right'; 1841 $table_summary->align[3] = 'left'; 1842 $table_summary->align[4] = 'right'; 1843 1844 $table_summary->head_colspan[0] = 2; 1845 $table_summary->head[0] = __('Min Value'); 1846 $table_summary->head[1] = __('Average Value'); 1847 $table_summary->head_colspan[2] = 2; 1848 $table_summary->head[2] = __('Max Value'); 1849 1850 $table_summary->data[0][0] = $item['min']['agent'] . ' - ' . $item['min']['module']; 1851 $table_summary->data[0][1] = $item['min']['formated_value']; 1852 $table_summary->data[0][2] = format_for_graph($item['avg_value'], 2); 1853 $table_summary->data[0][3] = $item['max']['agent'] . ' - ' . $item['max']['module']; 1854 $table_summary->data[0][4] = $item['max']['formated_value']; 1855 1856 $table->colspan['summary_title']['cell'] = 3; 1857 $table->data['summary_title']['cell'] = '<b>' . __('Summary') . '</b>'; 1858 $table->colspan['summary_table']['cell'] = 3; 1859 $table->data['summary_table']['cell'] = html_print_table($table_summary, true); 1860 } 1861} 1862 1863function reporting_html_sql(&$table, $item) { 1864 if (!$item['correct']) { 1865 $table->colspan['error']['cell'] = 3; 1866 $table->data['error']['cell'] = $item['error']; 1867 } 1868 else { 1869 $first = true; 1870 1871 $table2 = new stdClass(); 1872 $table2->class = 'databox'; 1873 $table2->width = '100%'; 1874 1875 foreach ($item['data'] as $row) { 1876 if ($first) { 1877 $first = false; 1878 1879 // Print the header 1880 foreach ($row as $key => $value) { 1881 $table2->head[] = $key; 1882 } 1883 } 1884 1885 $table2->data[] = $row; 1886 } 1887 1888 $table->colspan['data']['cell'] = 3; 1889 $table->cellstyle['data']['cell'] = 'text-align: center;'; 1890 $table->data['data']['cell'] = html_print_table($table2, true); 1891 } 1892} 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912function reporting_get_stats_summary($data, $graph_width, $graph_height) { 1913 global $config; 1914 1915 // Alerts table 1916 $table_sum = html_get_predefined_table(); 1917 1918 $tdata = array(); 1919 $table_sum->colspan[count($table_sum->data)][0] = 2; 1920 $table_sum->colspan[count($table_sum->data)][2] = 2; 1921 $table_sum->cellstyle[count($table_sum->data)][0] = 'text-align: center;'; 1922 $table_sum->cellstyle[count($table_sum->data)][2] = 'text-align: center;'; 1923 $tdata[0] = '<span class="med_data" style="color: #666">' . __('Module status') . '</span>'; 1924 $tdata[2] = '<span class="med_data" style="color: #666">' . __('Alert level') . '</span>'; 1925 $table_sum->rowclass[] = ''; 1926 $table_sum->data[] = $tdata; 1927 1928 $tdata = array(); 1929 $table_sum->colspan[count($table_sum->data)][0] = 2; 1930 $table_sum->colspan[count($table_sum->data)][2] = 2; 1931 $table_sum->cellstyle[count($table_sum->data)][0] = 'text-align: center;'; 1932 $table_sum->cellstyle[count($table_sum->data)][2] = 'text-align: center;'; 1933 1934 if ($data["monitor_checks"] > 0) { 1935 $tdata[0] = '<div style="margin: auto; width: ' . $graph_width . 'px;">' . graph_agent_status (false, $graph_width, $graph_height, true, true) . '</div>'; 1936 } 1937 else { 1938 $tdata[2] = html_print_image('images/image_problem.png', true, array('width' => $graph_width)); 1939 } 1940 if ($data["monitor_alerts"] > 0) { 1941 $tdata[2] = '<div style="margin: auto; width: ' . $graph_width . 'px;">' . graph_alert_status ($data["monitor_alerts"], $data["monitor_alerts_fired"], $graph_width, $graph_height, true, true) . '</div>'; 1942 } 1943 else { 1944 $tdata[2] = html_print_image('images/image_problem.png', true, array('width' => $graph_width)); 1945 } 1946 $table_sum->rowclass[] = ''; 1947 $table_sum->data[] = $tdata; 1948 1949 $output = '<fieldset class="databox tactical_set"> 1950 <legend>' . 1951 __('Summary') . 1952 '</legend>' . 1953 html_print_table($table_sum, true) . '</fieldset>'; 1954 1955 return $output; 1956} 1957 1958 1959 1960 1961 1962 1963/** 1964 * Get an event reporting table. 1965 * 1966 * It construct a table object with all the events happened in a group 1967 * during a period of time. 1968 * 1969 * @param int Group id to get the report. 1970 * @param int Period of time to get the report. 1971 * @param int Beginning date of the report 1972 * @param int Flag to return or echo the report table (echo by default). 1973 * 1974 * @return object A table object 1975 */ 1976function reporting_event_reporting ($id_group, $period, $date = 0, $return = false) { 1977 if (empty ($date)) { 1978 $date = get_system_time (); 1979 } 1980 elseif (!is_numeric ($date)) { 1981 $date = strtotime ($date); 1982 } 1983 1984 $table->data = array (); 1985 $table->head = array (); 1986 $table->head[0] = __('Status'); 1987 $table->head[1] = __('Event name'); 1988 $table->head[2] = __('User ID'); 1989 $table->head[3] = __('Timestamp'); 1990 1991 $events = events_get_group_events ($id_group, $period, $date); 1992 if (empty ($events)) { 1993 $events = array (); 1994 } 1995 foreach ($events as $event) { 1996 $data = array (); 1997 if ($event["estado"] == 0) 1998 $data[0] = html_print_image("images/dot_red.png", true); 1999 else 2000 $data[0] = html_print_image("images/dot_green.png", true); 2001 $data[1] = $event['evento']; 2002 $data[2] = $event['id_usuario'] != '0' ? $event['id_usuario'] : ''; 2003 $data[3] = $event["timestamp"]; 2004 array_push ($table->data, $data); 2005 } 2006 2007 if (empty ($return)) 2008 html_print_table ($table); 2009 2010 return $table; 2011} 2012 2013/** 2014 * Get a table report from a alerts fired array. 2015 * 2016 * @param array Alerts fired array. 2017 * @see function get_alerts_fired () 2018 * 2019 * @return object A table object with a report of the fired alerts. 2020 */ 2021function reporting_get_fired_alerts_table ($alerts_fired) { 2022 $agents = array (); 2023 global $config; 2024 2025 require_once ($config["homedir"].'/include/functions_alerts.php'); 2026 2027 foreach (array_keys ($alerts_fired) as $id_alert) { 2028 $alert_module = alerts_get_alert_agent_module ($id_alert); 2029 $template = alerts_get_alert_template ($id_alert); 2030 2031 /* Add alerts fired to $agents_fired_alerts indexed by id_agent */ 2032 $id_agent = db_get_value ('id_agente', 'tagente_modulo', 2033 'id_agente_modulo', $alert_module['id_agent_module']); 2034 if (!isset ($agents[$id_agent])) { 2035 $agents[$id_agent] = array (); 2036 } 2037 array_push ($agents[$id_agent], array ($alert_module, $template)); 2038 } 2039 2040 $table->data = array (); 2041 $table->head = array (); 2042 $table->head[0] = __('Agent'); 2043 $table->head[1] = __('Alert description'); 2044 $table->head[2] = __('Times fired'); 2045 $table->head[3] = __('Priority'); 2046 2047 foreach ($agents as $id_agent => $alerts) { 2048 $data = array (); 2049 foreach ($alerts as $tuple) { 2050 $alert_module = $tuple[0]; 2051 $template = $tuple[1]; 2052 if (! isset ($data[0])) 2053 $data[0] = agents_get_name ($id_agent); 2054 else 2055 $data[0] = ''; 2056 $data[1] = $template['name']; 2057 $data[2] = $alerts_fired[$alert_module['id']]; 2058 $data[3] = get_alert_priority ($alert_module['priority']); 2059 array_push ($table->data, $data); 2060 } 2061 } 2062 2063 return $table; 2064} 2065 2066/** 2067 * Get a report for alerts in a group of agents. 2068 * 2069 * It prints the numbers of alerts defined, fired and not fired in a group. 2070 * It also prints all the alerts that were fired grouped by agents. 2071 * 2072 * @param int $id_group Group to get info of the alerts. 2073 * @param int $period Period of time of the desired alert report. 2074 * @param int $date Beggining date of the report (current date by default). 2075 * @param bool $return Flag to return or echo the report (echo by default). 2076 * 2077 * @return string 2078 */ 2079function reporting_alert_reporting ($id_group, $period = 0, $date = 0, $return = false) { 2080 global $config; 2081 2082 $output = ''; 2083 $alerts = get_group_alerts ($id_group); 2084 $alerts_fired = get_alerts_fired ($alerts, $period, $date); 2085 2086 $fired_percentage = 0; 2087 if (sizeof ($alerts) > 0) 2088 $fired_percentage = round (sizeof ($alerts_fired) / sizeof ($alerts) * 100, 2); 2089 $not_fired_percentage = 100 - $fired_percentage; 2090 2091 $data = array (); 2092 $data[__('Alerts fired')] = $fired_percentage; 2093 $data[__('Alerts not fired')] = $not_fired_percentage; 2094 2095 $output .= pie3d_graph(false, $data, 280, 150, 2096 __("other"), 2097 ui_get_full_url(false, false, false, false) . '/', 2098 ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", 2099 $config['fontpath'], $config['font_size']); 2100 2101 $output .= '<strong>'.__('Alerts fired').': '.sizeof ($alerts_fired).'</strong><br />'; 2102 $output .= '<strong>'.__('Total alerts monitored').': '.sizeof ($alerts).'</strong><br />'; 2103 2104 if (! sizeof ($alerts_fired)) { 2105 if (!$return) 2106 echo $output; 2107 2108 return $output; 2109 } 2110 $table = reporting_get_fired_alerts_table ($alerts_fired); 2111 $table->width = '100%'; 2112 $table->class = 'databox'; 2113 $table->size = array (); 2114 $table->size[0] = '100px'; 2115 $table->style = array (); 2116 $table->style[0] = 'font-weight: bold'; 2117 2118 $output .= html_print_table ($table, true); 2119 2120 if (!$return) 2121 echo $output; 2122 2123 return $output; 2124} 2125 2126/** 2127 * Get a report for monitors modules in a group of agents. 2128 * 2129 * It prints the numbers of monitors defined, showing those which went up and down, in a group. 2130 * It also prints all the down monitors in the group. 2131 * 2132 * @param int $id_group Group to get info of the monitors. 2133 * @param int $period Period of time of the desired monitor report. 2134 * @param int $date Beginning date of the report in UNIX time (current date by default). 2135 * @param bool $return Flag to return or echo the report (by default). 2136 * 2137 * @return string 2138 */ 2139function reporting_monitor_health ($id_group, $period = 0, $date = 0, $return = false) { 2140 if (empty ($date)) //If date is 0, false or empty 2141 $date = get_system_time (); 2142 2143 $datelimit = $date - $period; 2144 $output = ''; 2145 2146 $monitors = modules_get_monitors_in_group ($id_group); 2147 if (empty ($monitors)) //If monitors has returned false or an empty array 2148 return; 2149 $monitors_down = modules_get_monitors_down ($monitors, $period, $date); 2150 $down_percentage = round (count ($monitors_down) / count ($monitors) * 100, 2); 2151 $not_down_percentage = 100 - $down_percentage; 2152 2153 $output .= '<strong>'.__('Total monitors').': '.count ($monitors).'</strong><br />'; 2154 $output .= '<strong>'.__('Monitors down on period').': '.count ($monitors_down).'</strong><br />'; 2155 2156 $table = reporting_get_monitors_down_table ($monitors_down); 2157 $table->width = '100%'; 2158 $table->class = 'databox'; 2159 $table->size = array (); 2160 $table->size[0] = '100px'; 2161 $table->style = array (); 2162 $table->style[0] = 'font-weight: bold'; 2163 2164 $table->size = array (); 2165 $table->size[0] = '100px'; 2166 2167 $output .= html_print_table ($table, true); 2168 2169 $data = array(); 2170 $data[__('Monitors OK')] = $down_percentage; 2171 $data[__('Monitors BAD')] = $not_down_percentage; 2172 2173 $output .= pie3d_graph(false, $data, 280, 150, 2174 __("other"), 2175 ui_get_full_url(false, false, false, false) . '/', 2176 ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", 2177 $config['fontpath'], $config['font_size']); 2178 2179 if (!$return) 2180 echo $output; 2181 2182 return $output; 2183} 2184 2185/** 2186 * Get a report table with all the monitors down. 2187 * 2188 * @param array An array with all the monitors down 2189 * @see function modules_get_monitors_down() 2190 * 2191 * @return object A table object with a monitors down report. 2192 */ 2193function reporting_get_monitors_down_table ($monitors_down) { 2194 $table->data = array (); 2195 $table->head = array (); 2196 $table->head[0] = __('Agent'); 2197 $table->head[1] = __('Monitor'); 2198 2199 $agents = array (); 2200 if ($monitors_down) { 2201 foreach ($monitors_down as $monitor) { 2202 /* Add monitors fired to $agents_fired_alerts indexed by id_agent */ 2203 $id_agent = $monitor['id_agente']; 2204 if (!isset ($agents[$id_agent])) { 2205 $agents[$id_agent] = array (); 2206 } 2207 array_push ($agents[$id_agent], $monitor); 2208 2209 $monitors_down++; 2210 } 2211 foreach ($agents as $id_agent => $monitors) { 2212 $data = array (); 2213 foreach ($monitors as $monitor) { 2214 if (! isset ($data[0])) 2215 $data[0] = agents_get_name ($id_agent); 2216 else 2217 $data[0] = ''; 2218 if ($monitor['descripcion'] != '') { 2219 $data[1] = $monitor['descripcion']; 2220 } 2221 else { 2222 $data[1] = $monitor['nombre']; 2223 } 2224 array_push ($table->data, $data); 2225 } 2226 } 2227 } 2228 2229 return $table; 2230} 2231 2232/** 2233 * Get a general report of a group of agents. 2234 * 2235 * It shows the number of agents and no more things right now. 2236 * 2237 * @param int Group to get the report 2238 * @param bool Flag to return or echo the report (by default). 2239 * 2240 * @return HTML string with group report 2241 */ 2242function reporting_print_group_reporting ($id_group, $return = false) { 2243 $agents = agents_get_group_agents ($id_group, false, "none"); 2244 $output = '<strong>' . 2245 sprintf(__('Agents in group: %s'), count($agents)) . 2246 '</strong><br />'; 2247 2248 if ($return === false) 2249 echo $output; 2250 2251 return $output; 2252} 2253 2254/** 2255 * Get a report table of the fired alerts group by agents. 2256 * 2257 * @param int Agent id to generate the report. 2258 * @param int Period of time of the report. 2259 * @param int Beginning date of the report in UNIX time (current date by default). 2260 * 2261 * @return object A table object with the alert reporting.. 2262 */ 2263function reporting_get_agent_alerts_table ($id_agent, $period = 0, $date = 0) { 2264 global $config; 2265 $table->data = array (); 2266 $table->head = array (); 2267 $table->head[0] = __('Type'); 2268 $table->head[1] = __('Description'); 2269 $table->head[2] = __('Value'); 2270 $table->head[3] = __('Threshold'); 2271 $table->head[4] = __('Last fired'); 2272 $table->head[5] = __('Times fired'); 2273 2274 require_once ($config["homedir"].'/include/functions_alerts.php'); 2275 2276 $alerts = agents_get_alerts ($id_agent); 2277 2278 foreach ($alerts['simple'] as $alert) { 2279 $fires = get_alert_fires_in_period ($alert['id'], $period, $date); 2280 if (! $fires) { 2281 continue; 2282 } 2283 2284 $template = alerts_get_alert_template ($alert['id_alert_template']); 2285 $data = array (); 2286 $data[0] = alerts_get_alert_templates_type_name ($template['type']); 2287 $data[1] = $template['name']; 2288 2289 switch ($template['type']) { 2290 case 'regex': 2291 if ($template['matches_value']) 2292 $data[2] = '≃ "'.$template['value'].'"'; 2293 else 2294 $data[2] = '≄ "'.$template['value'].'"'; 2295 break; 2296 case 'equal': 2297 case 'not_equal': 2298 $data[2] = $template['value']; 2299 2300 break; 2301 case 'max-min': 2302 $data[2] = __('Min.').': '.$template['min_value']. ' '; 2303 $data[2] .= __('Max.').': '.$template['max_value']. ' '; 2304 2305 break; 2306 case 'max': 2307 $data[2] = $template['max_value']; 2308 2309 break; 2310 case 'min': 2311 $data[2] = $template['min_value']; 2312 2313 break; 2314 } 2315 $data[3] = $template['time_threshold']; 2316 $data[4] = ui_print_timestamp (get_alert_last_fire_timestamp_in_period ($alert['id'], $period, $date), true); 2317 $data[5] = $fires; 2318 2319 array_push ($table->data, $data); 2320 } 2321 2322 return $table; 2323} 2324 2325/** 2326 * Get a report of monitors in an agent. 2327 * 2328 * @param int Agent id to get the report 2329 * @param int Period of time of the report. 2330 * @param int Beginning date of the report in UNIX time (current date by default). 2331 * 2332 * @return object A table object with the report. 2333 */ 2334function reporting_get_agent_monitors_table ($id_agent, $period = 0, $date = 0) { 2335 $n_a_string = __('N/A').'(*)'; 2336 $table->head = array (); 2337 $table->head[0] = __('Monitor'); 2338 $table->head[1] = __('Last failure'); 2339 $table->data = array (); 2340 $monitors = modules_get_monitors_in_agent ($id_agent); 2341 2342 if ($monitors === false) { 2343 return $table; 2344 } 2345 foreach ($monitors as $monitor) { 2346 $downs = modules_get_monitor_downs_in_period ($monitor['id_agente_modulo'], $period, $date); 2347 if (! $downs) { 2348 continue; 2349 } 2350 $data = array (); 2351 if ($monitor['descripcion'] != $n_a_string && $monitor['descripcion'] != '') 2352 $data[0] = $monitor['descripcion']; 2353 else 2354 $data[0] = $monitor['nombre']; 2355 $data[1] = modules_get_last_down_timestamp_in_period ($monitor['id_agente_modulo'], $period, $date); 2356 array_push ($table->data, $data); 2357 } 2358 2359 return $table; 2360} 2361 2362/** 2363 * Get a report of all the modules in an agent. 2364 * 2365 * @param int Agent id to get the report. 2366 * @param int Period of time of the report 2367 * @param int Beginning date of the report in UNIX time (current date by default). 2368 * 2369 * @return object 2370 */ 2371function reporting_get_agent_modules_table ($id_agent, $period = 0, $date = 0) { 2372 $table->data = array (); 2373 $n_a_string = __('N/A').'(*)'; 2374 $modules = agents_get_modules ($id_agent, array ("nombre", "descripcion")); 2375 if ($modules === false) 2376 $modules = array(); 2377 $data = array (); 2378 2379 foreach ($modules as $module) { 2380 if ($module['descripcion'] != $n_a_string && $module['descripcion'] != '') 2381 $data[0] = $module['descripcion']; 2382 else 2383 $data[0] = $module['nombre']; 2384 array_push ($table->data, $data); 2385 } 2386 2387 return $table; 2388} 2389 2390/** 2391 * Get a detailed report of an agent 2392 * 2393 * @param int Agent to get the report. 2394 * @param int Period of time of the desired report. 2395 * @param int Beginning date of the report in UNIX time (current date by default). 2396 * @param bool Flag to return or echo the report (by default). 2397 * 2398 * @return string 2399 */ 2400function reporting_get_agent_detailed ($id_agent, $period = 0, $date = 0, $return = false) { 2401 $output = ''; 2402 $n_a_string = __('N/A(*)'); 2403 2404 /* Show modules in agent */ 2405 $output .= '<div class="agent_reporting">'; 2406 $output .= '<h3 style="text-decoration: underline">' . 2407 __('Agent') . ' - ' . agents_get_name ($id_agent) . '</h3>'; 2408 $output .= '<h4>'.__('Modules').'</h3>'; 2409 $table_modules = reporting_get_agent_modules_table ($id_agent, $period, $date); 2410 $table_modules->width = '99%'; 2411 $output .= html_print_table ($table_modules, true); 2412 2413 /* Show alerts in agent */ 2414 $table_alerts = reporting_get_agent_alerts_table ($id_agent, $period, $date); 2415 $table_alerts->width = '99%'; 2416 if (sizeof ($table_alerts->data)) { 2417 $output .= '<h4>'.__('Alerts').'</h4>'; 2418 $output .= html_print_table ($table_alerts, true); 2419 } 2420 2421 /* Show monitor status in agent (if any) */ 2422 $table_monitors = reporting_get_agent_monitors_table ($id_agent, $period, $date); 2423 if (sizeof ($table_monitors->data) == 0) { 2424 $output .= '</div>'; 2425 if (! $return) 2426 echo $output; 2427 return $output; 2428 } 2429 $table_monitors->width = '99%'; 2430 $table_monitors->align = array (); 2431 $table_monitors->align[1] = 'right'; 2432 $table_monitors->size = array (); 2433 $table_monitors->align[1] = '10%'; 2434 $output .= '<h4>'.__('Monitors').'</h4>'; 2435 $output .= html_print_table ($table_monitors, true); 2436 2437 $output .= '</div>'; 2438 2439 if (! $return) 2440 echo $output; 2441 return $output; 2442} 2443 2444/** 2445 * Get a detailed report of agents in a group. 2446 * 2447 * @param mixed Group(s) to get the report 2448 * @param int Period 2449 * @param int Timestamp to start from 2450 * @param bool Flag to return or echo the report (by default). 2451 * 2452 * @return string 2453 */ 2454function reporting_agents_get_group_agents_detailed ($id_group, $period = 0, $date = 0, $return = false) { 2455 $agents = agents_get_group_agents ($id_group, false, "none"); 2456 2457 $output = ''; 2458 foreach ($agents as $agent_id => $agent_name) { 2459 $output .= reporting_get_agent_detailed ($agent_id, $period, $date, true); 2460 } 2461 2462 if ($return === false) 2463 echo $output; 2464 2465 return $output; 2466} 2467 2468 2469 2470 2471 2472/** 2473 * This is the callback sorting function for SLA values descending 2474 * 2475 * @param array $a Array element 1 to compare 2476 * @param array $b Array element 2 to compare 2477 * 2478 */ 2479function sla_value_desc_cmp($a, $b) { 2480 // This makes 'Unknown' values the lastest 2481 if (preg_match('/^(.)*Unknown(.)*$/', $a[5])) 2482 $a[6] = -1; 2483 2484 if (preg_match('/^(.)*Unknown(.)*$/', $b[5])) 2485 $b[6] = -1; 2486 2487 return ($a[6] < $b[6])? 1 : 0; 2488} 2489 2490/** 2491 * This is the callback sorting function for SLA values ascending 2492 * 2493 * @param array $a Array element 1 to compare 2494 * @param array $b Array element 2 to compare 2495 * 2496 */ 2497function sla_value_asc_cmp($a, $b) { 2498 // This makes 'Unknown' values the lastest 2499 if (preg_match('/^(.)*Unknown(.)*$/', $a[5])) 2500 $a[6] = -1; 2501 2502 if (preg_match('/^(.)*Unknown(.)*$/', $b[5])) 2503 $b[6] = -1; 2504 2505 return ($a[6] > $b[6])? 1 : 0; 2506} 2507 2508/** 2509 * Make the header for each content. 2510 */ 2511function reporting_header_content($mini, $content, $report, &$table, 2512 $title = false, $name = false, $period = false) { 2513 2514 global $config; 2515 2516 if ($mini) { 2517 $sizh = ''; 2518 $sizhfin = ''; 2519 } 2520 else { 2521 $sizh = '<h4>'; 2522 $sizhfin = '</h4>'; 2523 } 2524 2525 $data = array(); 2526 2527 $count_empty = 0; 2528 2529 if ($title !== false) { 2530 $data[] = $sizh . $title . $sizhfin; 2531 } 2532 else $count_empty++; 2533 2534 if ($name !== false) { 2535 $data[] = $sizh . $name . $sizhfin; 2536 } 2537 else $count_empty++; 2538 2539 if ($period !== false && $content['period'] > 0) { 2540 $data[] = $sizh . $period . $sizhfin; 2541 } 2542 else if ($content['period'] == 0) { 2543 $es = json_decode($content['external_source'], true); 2544 if ($es['date'] == 0) { 2545 $date = __('Last data'); 2546 } 2547 else { 2548 $date = date($config["date_format"], $es['date']); 2549 } 2550 2551 $data[] = "<div style='text-align: right;'>" . $sizh . $date . $sizhfin . "</div>"; 2552 } 2553 else { 2554 $data[] = "<div style='text-align: right;'>" . $sizh . 2555 "(" . human_time_description_raw ($content['period']) . ") " . 2556 __("From:") . " " . date($config["date_format"], $report["datetime"] - $content['period']) . "<br />" . 2557 __("To:") . " " . date($config["date_format"], $report["datetime"]) . "<br />" . 2558 $sizhfin . "</div>"; 2559 } 2560 2561 $table->colspan[0][2 - $count_empty] = 1 + $count_empty; 2562 2563 array_push ($table->data, $data); 2564} 2565 2566function reporting_get_agents_by_status ($data, $graph_width = 250, $graph_height = 150, $links = false) { 2567 global $config; 2568 2569 if ($links == false) { 2570 $links = array(); 2571 } 2572 2573 $table_agent = html_get_predefined_table(); 2574 2575 $agent_data = array(); 2576 $agent_data[0] = html_print_image('images/agent_critical.png', true, array('title' => __('Agents critical'))); 2577 $agent_data[1] = "<a style='color: ".COL_CRITICAL.";' href='" . $links['agents_critical'] . "'><b><span style='font-size: 12pt; font-weight: bold; color: #FC4444;'>".format_numeric($data['agent_critical'])."</span></b></a>"; 2578 2579 $agent_data[2] = html_print_image('images/agent_warning.png', true, array('title' => __('Agents warning'))); 2580 $agent_data[3] = "<a style='color: ".COL_WARNING.";' href='" . $links['agents_warning'] . "'><b><span style='font-size: 12pt; font-weight: bold; color: #FAD403;'>".format_numeric($data['agent_warning'])."</span></b></a>"; 2581 2582 $table_agent->data[] = $agent_data; 2583 2584 $agent_data = array(); 2585 $agent_data[0] = html_print_image('images/agent_ok.png', true, array('title' => __('Agents ok'))); 2586 $agent_data[1] = "<a style='color: ".COL_NORMAL.";' href='" . $links['agents_ok'] . "'><b><span style='font-size: 12pt; font-weight: bold; color: #80BA27;'>".format_numeric($data['agent_ok'])."</span></b></a>"; 2587 2588 $agent_data[2] = html_print_image('images/agent_unknown.png', true, array('title' => __('Agents unknown'))); 2589 $agent_data[3] = "<a style='color: ".COL_UNKNOWN.";' href='" . $links['agents_unknown'] . "'><b><span style='font-size: 12pt; font-weight: bold; color: #B2B2B2;'>".format_numeric($data['agent_unknown'])."</span></b></a>"; 2590 2591 $table_agent->data[] = $agent_data; 2592 2593 $agent_data = array(); 2594 $agent_data[0] = html_print_image('images/agent_notinit.png', true, array('title' => __('Agents not init'))); 2595 $agent_data[1] = "<a style='color: ".COL_NOTINIT.";' href='" . $links['agents_not_init'] . "'><b><span style='font-size: 12pt; font-weight: bold; color: #5BB6E5;'>".format_numeric($data['agent_not_init'])."</span></b></a>"; 2596 2597 $agent_data[2] = ""; 2598 $agent_data[3] = ""; 2599 $table_agent->data[] = $agent_data; 2600 2601 2602 if (!defined('METACONSOLE')) { 2603 $agents_data = '<fieldset class="databox tactical_set"> 2604 <legend>' . 2605 __('Agents by status') . 2606 '</legend>' . 2607 html_print_table($table_agent, true) . '</fieldset>'; 2608 } 2609 else { 2610 $table_agent->style=array(); 2611 $table_agent->class = "tactical_view"; 2612 $agents_data = '<fieldset class="tactical_set"> 2613 <legend>' . 2614 __('Agents by status') . 2615 '</legend>' . 2616 html_print_table($table_agent, true) . '</fieldset>'; 2617 } 2618 2619 return $agents_data; 2620} 2621 2622function reporting_get_total_agents_and_monitors ($data, $graph_width = 250, $graph_height = 150) { 2623 global $config; 2624 2625 $total_agent = $data['agent_ok'] + $data['agent_warning'] + $data['agent_critical'] + $data['gent_unknown'] + $data['agent_not_init']; 2626 $total_module = $data['monitor_ok'] + $data['monitor_warning'] + $data['monitor_critical'] + $data['monitor_unknown'] + $data['monitor_not_init']; 2627 2628 $table_total = html_get_predefined_table(); 2629 2630 $total_data = array(); 2631 $total_data[0] = html_print_image('images/agent.png', true, array('title' => __('Total agents'))); 2632 $total_data[1] = $total_agent <= 0 ? '-' : $total_agent; 2633 $total_data[2] = html_print_image('images/module.png', true, array('title' => __('Monitor checks'))); 2634 $total_data[3] = $total_module <= 0 ? '-' : $total_module; 2635 $table_total->data[] = $total_data; 2636 $total_agent_module = '<fieldset class="databox tactical_set"> 2637 <legend>' . 2638 __('Total agents and monitors') . 2639 '</legend>' . 2640 html_print_table($table_total, true) . '</fieldset>'; 2641 2642 return $total_agent_module; 2643} 2644 2645function reporting_get_total_servers ($num_servers) { 2646 global $config; 2647 2648 $table_node = html_get_predefined_table(); 2649 2650 $node_data = array(); 2651 $node_data[0] = html_print_image('images/server_export.png', true, array('title' => __('Nodes'))); 2652 $node_data[1] = "<b><span style='font-size: 12pt; font-weight: bold; color: black;'>".format_numeric($num_servers)."</span></b>"; 2653 $table_node->data[] = $node_data; 2654 2655 if (!defined('METACONSOLE')) { 2656 $node_overview = '<fieldset class="databox tactical_set"> 2657 <legend>' . 2658 __('Node overview') . 2659 '</legend>' . 2660 html_print_table($table_node, true) . '</fieldset>'; 2661 } 2662 else { 2663 $table_node->style = array(); 2664 $table_node->class = "tactical_view"; 2665 $node_overview = '<fieldset class="tactical_set"> 2666 <legend>' . 2667 __('Node overview') . 2668 '</legend>' . 2669 html_print_table($table_node, true) . '</fieldset>'; 2670 } 2671 2672 return $node_overview; 2673} 2674 2675function reporting_get_events ($data, $links = false) { 2676 global $config; 2677 2678 $table_events->width = "100%"; 2679 if (defined('METACONSOLE')) 2680 $style = " vertical-align:middle;"; 2681 else 2682 $style = ""; 2683 if (defined('METACONSOLE')) { 2684 $table_events->style[0] = "background-color:#FC4444"; 2685 $table_events->data[0][0] = html_print_image('images/module_event_critical.png', true, array('title' => __('Critical events'))); 2686 $table_events->data[0][0] .= " " . 2687 "<a style='color:#FFF; font-size: 12pt; font-weight: bold;" . $style . "' href='" . $links['critical'] . "'>" . format_numeric($data['critical'])."</a>"; 2688 $table_events->style[1] = "background-color:#FAD403"; 2689 $table_events->data[0][1] = html_print_image('images/module_event_warning.png', true, array('title' => __('Warning events'))); 2690 $table_events->data[0][1] .= " " . 2691 "<a style='color:#FFF; font-size: 12pt; font-weight: bold;" . $style . "' href='" . $links['warning'] . "'>" . format_numeric($data['warning'])."</a>"; 2692 $table_events->style[2] = "background-color:#80BA27"; 2693 $table_events->data[0][2] = html_print_image('images/module_event_ok.png', true, array('title' => __('OK events'))); 2694 $table_events->data[0][2] .= " " . 2695 "<a style='color:#FFF; font-size: 12pt; font-weight: bold;" . $style . "' href='" . $links['normal'] . "'>" . format_numeric($data['normal'])."</a>"; 2696 $table_events->style[3] = "background-color:#B2B2B2"; 2697 $table_events->data[0][3] = html_print_image('images/module_event_unknown.png', true, array('title' => __('Unknown events'))); 2698 $table_events->data[0][3] .= " " . 2699 "<a style='color:#FFF; font-size: 12pt; font-weight: bold;" . $style . "' href='" . $links['unknown'] . "'>" . format_numeric($data['unknown'])."</a>"; 2700 } 2701 else { 2702 $table_events->data[0][0] = html_print_image('images/module_critical.png', true, array('title' => __('Critical events'))); 2703 $table_events->data[0][0] .= " " . 2704 "<a style='color: #FC4444;" . $style . "' href='" . $links['critical'] . "'><b><span style='font-size: 12pt; font-weight: bold; color: #FC4444;'>". 2705 format_numeric($data['critical'])."</span></b></a>"; 2706 $table_events->data[0][1] = html_print_image('images/module_warning.png', true, array('title' => __('Warning events'))); 2707 $table_events->data[0][1] .= " " . 2708 "<a style='color: #FAD403;" . $style . "' href='" . $links['warning'] . "'><b><span style='font-size: 12pt; font-weight: bold; color: #FAD403;'>". 2709 format_numeric($data['warning'])."</span></b></a>"; 2710 $table_events->data[0][2] = html_print_image('images/module_ok.png', true, array('title' => __('OK events'))); 2711 $table_events->data[0][2] .= " " . 2712 "<a style='color: #80BA27;" . $style . "' href='" . $links['normal'] . "'><b style='font-size: 12pt; font-weight: bold; color: #80BA27;'>". 2713 format_numeric($data['normal'])."</b></a>"; 2714 $table_events->data[0][3] = html_print_image('images/module_unknown.png', true, array('title' => __('Unknown events'))); 2715 $table_events->data[0][3] .= " " . 2716 "<a style='color: #B2B2B2;" . $style . "' href='" . $links['unknown'] . "'><b><span style='font-size: 12pt; font-weight: bold; color: #B2B2B2;'>". 2717 format_numeric($data['unknown'])."</span></b></a>"; 2718 2719 } 2720 if (!defined('METACONSOLE')) { 2721 $event_view = '<fieldset class="databox tactical_set"> 2722 <legend>' . 2723 __('Events by severity') . 2724 '</legend>' . 2725 html_print_table($table_events, true) . '</fieldset>'; 2726 } 2727 else { 2728 $table_events->class="tactical_view"; 2729 $table_events->styleTable="text-align:center;"; 2730 $table_events->size[0]="10%"; 2731 $table_events->size[1]="10%"; 2732 $table_events->size[2]="10%"; 2733 $table_events->size[3]="10%"; 2734 2735 $event_view = '<fieldset class="tactical_set"> 2736 <legend>' . 2737 __('Important Events by Criticity') . 2738 '</legend>' . 2739 html_print_table($table_events, true) . '</fieldset>'; 2740 } 2741 2742 return $event_view; 2743} 2744 2745function reporting_get_last_activity() { 2746 global $config; 2747 2748 // Show last activity from this user 2749 2750 $table->width = '100%'; 2751 $table->data = array (); 2752 $table->size = array (); 2753 $table->size[2] = '150px'; 2754 $table->size[3] = '130px'; 2755 $table->size[5] = '200px'; 2756 $table->head = array (); 2757 $table->head[0] = __('User'); 2758 $table->head[1] = ''; 2759 $table->head[2] = __('Action'); 2760 $table->head[3] = __('Date'); 2761 $table->head[4] = __('Source IP'); 2762 $table->head[5] = __('Comments'); 2763 $table->title = '<span>' . __('Last activity in Pandora FMS console') . '</span>'; 2764 2765 switch ($config["dbtype"]) { 2766 case "mysql": 2767 $sql = sprintf ("SELECT id_usuario,accion,fecha,ip_origen,descripcion,utimestamp 2768 FROM tsesion 2769 WHERE (`utimestamp` > UNIX_TIMESTAMP(NOW()) - " . SECONDS_1WEEK . ") 2770 AND `id_usuario` = '%s' ORDER BY `utimestamp` DESC LIMIT 5", $config["id_user"]); 2771 break; 2772 case "postgresql": 2773 $sql = sprintf ("SELECT \"id_usuario\", accion, fecha, \"ip_origen\", descripcion, utimestamp 2774 FROM tsesion 2775 WHERE (\"utimestamp\" > ceil(date_part('epoch', CURRENT_TIMESTAMP)) - " . SECONDS_1WEEK . ") 2776 AND \"id_usuario\" = '%s' ORDER BY \"utimestamp\" DESC LIMIT 5", $config["id_user"]); 2777 break; 2778 case "oracle": 2779 $sql = sprintf ("SELECT id_usuario, accion, fecha, ip_origen, descripcion, utimestamp 2780 FROM tsesion 2781 WHERE ((utimestamp > ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) * (" . SECONDS_1DAY . ")) - " . SECONDS_1WEEK . ") 2782 AND id_usuario = '%s') AND rownum <= 10 ORDER BY utimestamp DESC", $config["id_user"]); 2783 break; 2784 } 2785 2786 $sessions = db_get_all_rows_sql ($sql); 2787 2788 if ($sessions === false) 2789 $sessions = array (); 2790 2791 foreach ($sessions as $session) { 2792 $data = array (); 2793 2794 switch ($config["dbtype"]) { 2795 case "mysql": 2796 case "oracle": 2797 $session_id_usuario = $session['id_usuario']; 2798 $session_ip_origen = $session['ip_origen']; 2799 break; 2800 case "postgresql": 2801 $session_id_usuario = $session['id_usuario']; 2802 $session_ip_origen = $session['ip_origen']; 2803 break; 2804 } 2805 2806 2807 $data[0] = '<strong>' . $session_id_usuario . '</strong>'; 2808 $data[1] = ui_print_session_action_icon ($session['accion'], true); 2809 $data[2] = $session['accion']; 2810 $data[3] = ui_print_help_tip($session['fecha'], true) . human_time_comparation($session['utimestamp'], 'tiny'); 2811 $data[4] = $session_ip_origen; 2812 $data[5] = io_safe_output ($session['descripcion']); 2813 2814 array_push ($table->data, $data); 2815 } 2816 2817 if(defined("METACONSOLE")) 2818 $table->class="databox_tactical"; 2819 2820 return html_print_table ($table, true); 2821 2822} 2823 2824function reporting_get_event_histogram ($events, $text_header_event = false) { 2825 global $config; 2826 if (!defined("METACONSOLE")) { 2827 include_once ($config['homedir'] .'/include/graphs/functions_gd.php'); 2828 } 2829 else { 2830 include_once ('../../include/graphs/functions_gd.php'); 2831 } 2832 2833 $max_value = count($events); 2834 2835 if (defined("METACONSOLE")) 2836 $max_value = SECONDS_1HOUR; 2837 2838 if (!$text_header_event) { 2839 $text_header_event = __('Events info (1hr.)'); 2840 } 2841 2842 $ttl = 1; 2843 $urlImage = ui_get_full_url(false, true, false, false); 2844 2845 $colors = array( 2846 EVENT_CRIT_MAINTENANCE => COL_MAINTENANCE, 2847 EVENT_CRIT_INFORMATIONAL => COL_INFORMATIONAL, 2848 EVENT_CRIT_NORMAL => COL_NORMAL, 2849 EVENT_CRIT_MINOR => COL_MINOR, 2850 EVENT_CRIT_WARNING => COL_WARNING, 2851 EVENT_CRIT_MAJOR => COL_MAJOR, 2852 EVENT_CRIT_CRITICAL => COL_CRITICAL 2853 ); 2854 2855 if (defined("METACONSOLE")) { 2856 $full_legend = array(); 2857 $cont = 0; 2858 } 2859 2860 foreach ($events as $data) { 2861 2862 switch ($data['criticity']) { 2863 case 0: 2864 $color = EVENT_CRIT_MAINTENANCE; 2865 break; 2866 case 1: 2867 $color = EVENT_CRIT_INFORMATIONAL; 2868 break; 2869 case 2: 2870 $color = EVENT_CRIT_NORMAL; 2871 break; 2872 case 3: 2873 $color = EVENT_CRIT_WARNING; 2874 break; 2875 case 4: 2876 $color = EVENT_CRIT_CRITICAL; 2877 break; 2878 case 5: 2879 $color = EVENT_CRIT_MINOR; 2880 break; 2881 case 6: 2882 $color = EVENT_CRIT_MAJOR; 2883 break; 2884 case 20: 2885 $color = EVENT_CRIT_NOT_NORMAL; 2886 break; 2887 case 34: 2888 $color = EVENT_CRIT_WARNING_OR_CRITICAL; 2889 break; 2890 } 2891 2892 if (defined("METACONSOLE")) { 2893 $full_legend[$cont] = $data['timestamp']; 2894 $graph_data[] = array( 2895 'data' => $color, 2896 'utimestamp' => $data['utimestamp'] - get_system_time () 2897 ); 2898 $cont++; 2899 } 2900 else { 2901 $graph_data[] = array( 2902 'data' => $color, 2903 'utimestamp' => 1 2904 ); 2905 } 2906 } 2907 if (!$text_header_event) { 2908 $table->width = '100%'; 2909 } 2910 else { 2911 if (defined("METACONSOLE")) { 2912 $table->width = '100%'; 2913 } 2914 else { 2915 $table->width = '70%'; 2916 } 2917 } 2918 $table->data = array (); 2919 $table->size = array (); 2920 $table->head = array (); 2921 $table->title = '<span>' . $text_header_event . '</span>'; 2922 $table->data[0][0] = "" ; 2923 2924 if (!empty($graph_data)) { 2925 if (defined("METACONSOLE")) 2926 $slicebar = flot_slicesbar_graph($graph_data, $max_value, "100%", 35, $full_legend, $colors, $config['fontpath'], $config['round_corner'], $url); 2927 else { 2928 if (!$text_header_event) { 2929 $slicebar = slicesbar_graph($graph_data, $max_value, 700, 25, $colors, $config['fontpath'], $config['round_corner'], $urlImage, $ttl); 2930 } 2931 else { 2932 $slicebar = slicesbar_graph($graph_data, $max_value, 350, 18, $colors, $config['fontpath'], $config['round_corner'], $urlImage, $ttl); 2933 } 2934 } 2935 2936 2937 $table->data[0][0] = $slicebar; 2938 } 2939 else { 2940 $table->data[0][0] = __('No events'); 2941 } 2942 2943 if (!defined('METACONSOLE')) { 2944 if (!$text_header_event) { 2945 $event_graph = '<fieldset class="databox tactical_set"> 2946 <legend>' . 2947 $text_header_event . 2948 '</legend>' . 2949 html_print_table($table, true) . '</fieldset>'; 2950 } 2951 else { 2952 $table->class = 'noclass'; 2953 $event_graph = html_print_table($table, true); 2954 } 2955 } 2956 else { 2957 $table->class='tactical_view'; 2958 $event_graph = '<fieldset id="event_tactical" class="tactical_set">' . 2959 html_print_table($table, true) . '</fieldset>'; 2960 } 2961 2962 return $event_graph; 2963} 2964 2965function reporting_html_planned_downtimes_table ($planned_downtimes) { 2966 global $config; 2967 2968 if (empty($planned_downtimes)) 2969 return false; 2970 2971 require_once ($config['homedir'] . '/include/functions_planned_downtimes.php'); 2972 2973 $downtime_malformed = false; 2974 $malformed_planned_downtimes = planned_downtimes_get_malformed(); 2975 2976 $table = new StdClass(); 2977 $table->width = '99%'; 2978 $table->title = __('This SLA has been affected by the following planned downtimes'); 2979 $table->head = array(); 2980 $table->head[0] = __('Name'); 2981 $table->head[1] = __('Description'); 2982 $table->head[2] = __('Execution'); 2983 $table->head[3] = __('Dates'); 2984 $table->headstyle = array(); 2985 $table->style = array(); 2986 $table->data = array(); 2987 2988 if ($for_pdf) { 2989 $table->titlestyle = 'background: #373737; color: #FFF; display: table-cell; font-size: 12px; border: 1px solid grey'; 2990 $table->class = 'table_sla table_beauty'; 2991 2992 for ($i = 0; $i < count($table->head); $i++) { 2993 $table->headstyle[$i] = 'background: #666; color: #FFF; display: table-cell; font-size: 11px; border: 1px solid grey'; 2994 } 2995 for ($i = 0; $i < count($table->head); $i++) { 2996 $table->style[$i] = 'display: table-cell; font-size: 10px;'; 2997 } 2998 } 2999 3000 foreach ($planned_downtimes as $planned_downtime) { 3001 $data = array(); 3002 $data[0] = $planned_downtime['name']; 3003 $data[1] = $planned_downtime['description']; 3004 $data[2] = $planned_downtime['execution']; 3005 $data[3] = $planned_downtime['dates']; 3006 3007 if (!empty($malformed_planned_downtimes) && isset($malformed_planned_downtimes[$planned_downtime['id']])) { 3008 $next_row_num = count($table->data); 3009 $table->cellstyle[$next_row_num][0] = 'color: red'; 3010 $table->cellstyle[$next_row_num][1] = 'color: red'; 3011 $table->cellstyle[$next_row_num][2] = 'color: red'; 3012 $table->cellstyle[$next_row_num][3] = 'color: red'; 3013 3014 if (!$downtime_malformed) 3015 $downtime_malformed = true; 3016 } 3017 3018 $table->data[] = $data; 3019 } 3020 3021 $downtimes_table = ''; 3022 3023 if ($downtime_malformed) { 3024 $info_malformed = ui_print_error_message(__('This item is affected by a malformed planned downtime') . ". " . 3025 __('Go to the planned downtimes section to solve this') . ".", '', true); 3026 $downtimes_table .= $info_malformed; 3027 } 3028 3029 $downtimes_table .= html_print_table($table, true); 3030 3031 return $downtimes_table; 3032} 3033 3034?> 3035