Merge branch 'maint/7.0'
[ninja.git] / modules / reports / helpers / alert_history.php
blobac819e3d6a394776285de2714614af6e2209bfe6
1 <?php defined('SYSPATH') OR die('No direct access allowed.');
2 /**
3 * Helper class for alert log
5 * Copyright 2009 op5 AB
6 * op5, and the op5 logo are trademarks, servicemarks, registered servicemarks
7 * or registered trademarks of op5 AB.
8 * All other trademarks, servicemarks, registered trademarks, and registered
9 * servicemarks mentioned herein may be the property of their respective owner(s).
10 * The information contained herein is provided AS IS with NO WARRANTY OF ANY
11 * KIND, INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY, AND FITNESS FOR A
12 * PARTICULAR PURPOSE.
14 class alert_history {
15 /**
16 * Convert all sorts of constants to user-readable strings, add html, and generally make things pretty
17 * @param $entry A database row
18 * @return An array, somewhat similar to the entry one, but with new values
20 public static function get_user_friendly_representation($entry) {
21 $ret = array(
22 'type' => '',
23 'obj_name' => '',
24 'state' => '',
25 'image' => '',
26 'softorhard' => ''
28 switch ($entry['event_type']) {
29 case 100:
30 $ret['type'] = 'Process start';
31 $ret['state'] = "Start";
32 $ret['image'] = html::image(ninja::add_path('icons/16x16/'.strtolower($ret['state']).'.png'), array('alt' => _($ret['state']), 'title' => _($ret['state'])));
33 break;
34 case 102:
35 $ret['type'] = 'Process restart';
36 $ret['state'] = "Restart";
37 $ret['image'] = html::image(ninja::add_path('icons/16x16/'.strtolower($ret['state']).'.gif'), array('alt' => _($ret['state']), 'title' => _($ret['state'])));
38 break;
39 case 103:
40 $ret['type'] = 'Process shutdown';
41 $ret['state'] = 'Stop';
42 $ret['image'] = html::image(ninja::add_path('icons/16x16/'.strtolower($ret['state']).'.png'), array('alt' => _($ret['state']), 'title' => _($ret['state'])));
43 break;
44 case 701:
45 $ret['type'] = 'Service alert';
46 switch ($entry['state']) {
47 case 0:
48 $ret['state'] = 'OK';
49 break;
50 case 1:
51 $ret['state'] = 'Warning';
52 break;
53 case 2:
54 $ret['state'] = 'Critical';
55 break;
56 case 3:
57 $ret['state'] = 'Unknown';
58 break;
59 default:
60 # technically, "unknown unknown, as opposed to known unknown above"
61 $ret['state'] = 'Pending';
62 break;
64 $ret['image'] = html::image(ninja::add_path('icons/16x16/shield-'.strtolower($ret['state']).'.png'), array('alt' => _($ret['state']), 'title' => _($ret['state'])));
65 $ret['softorhard'] = $entry['hard'] ? 'Hard' : 'Soft';
66 break;
67 case 801:
68 $ret['type'] = 'Host alert';
69 switch ($entry['state']) {
70 case 0:
71 $ret['state'] = 'Up';
72 break;
73 case 1:
74 $ret['state'] = 'Down';
75 break;
76 case 2:
77 $ret['state'] = 'Unreachable';
78 break;
79 default:
80 $ret['state'] = 'Pending';
81 break;
83 $ret['image'] = html::image(ninja::add_path('icons/16x16/shield-'.strtolower($ret['state']).'.png'), array('alt' => _($ret['state']), 'title' => _($ret['state'])));
84 $ret['softorhard'] = $entry['hard'] ? 'Hard' : 'Soft';
85 break;
86 case 1103:
87 case 1104:
88 if ($entry['service_description'])
89 $ret['type'] = 'Service downtime alert';
90 else
91 $ret['type'] = 'Host downtime alert';
92 $ret['softorhard'] = $entry['event_type'] == 1103 ? 'Started' : 'Stopped';
93 $ret['image'] = html::image(ninja::add_path('icons/16x16/scheduled-downtime.png'), array('alt' => _('Scheduled downtime'), 'title' => _('Scheduled downtime')));
94 break;
95 default:
96 $ret['type'] = "Unknown event #{$entry['entry_type']}";
97 break;
100 return $ret;