-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpriorityobjects.inc.php
More file actions
231 lines (193 loc) · 10.1 KB
/
priorityobjects.inc.php
File metadata and controls
231 lines (193 loc) · 10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<?php
//
// Priority Objects Component
// Copyright (c) 2024 NRDS. All rights reserved.
// Author: SNapier
//
require_once(dirname(__FILE__) . '/../componenthelper.inc.php');
$priorityobjects_component_name = "priorityobjects";
priorityobjects_component_init();
////////////////////////////////////////////////////////////////////////
// COMPONENT INIT FUNCTIONS
////////////////////////////////////////////////////////////////////////
function priorityobjects_component_init()
{
global $priorityobjects_component_name;
$desc = _('Visualizes high-priority hosts and services based on ServiceNow impact/urgency calculation.');
if (!priorityobjects_component_checkversion()) {
$desc = "<b>" . _('Error: This component requires Nagios XI 5.6.0 or later.') . "</b>";
}
$args = array(
COMPONENT_NAME => $priorityobjects_component_name,
COMPONENT_AUTHOR => "SNapier (NRDS)",
COMPONENT_DESCRIPTION => $desc,
COMPONENT_TITLE => _('Priority Objects'),
COMPONENT_VERSION => '1.5.3',
COMPONENT_DATE => '12/30/2025',
COMPONENT_TYPE => COMPONENT_TYPE_USER,
COMPONENT_PROTECTED => false,
COMPONENT_CONFIGFUNCTION => "priorityobjects_component_config_func"
);
register_component($priorityobjects_component_name, $args);
if (priorityobjects_component_checkversion()) {
register_callback(CALLBACK_MENUS_INITIALIZED, 'priorityobjects_component_addmenu');
}
}
////////////////////////////////////////////////////////////////////////
// VERSION CHECK
////////////////////////////////////////////////////////////////////////
function priorityobjects_component_checkversion()
{
if (!function_exists('get_product_release')) {
return false;
}
if (get_product_release() < 5600) {
return false;
}
return true;
}
////////////////////////////////////////////////////////////////////////
// MENU INTEGRATION
////////////////////////////////////////////////////////////////////////
function priorityobjects_component_addmenu($arg = null)
{
global $priorityobjects_component_name;
$component_url = get_component_url_base($priorityobjects_component_name);
// Find the Details section
$menu_section = find_menu_item(MENU_HOME, "menu-home-section-details", "id");
if ($menu_section == null) {
return false;
}
$order = grab_array_var($menu_section, "order", "");
if ($order == "") {
return false;
}
// Add menu item in Details section - 3rd from bottom
// Details section ends at order 230, so 227 is 3rd from bottom
$new_order = 227;
add_menu_item(MENU_HOME, array(
"type" => "link",
"title" => _("Priority Objects"),
"id" => "menu-home-details-priorityobjects",
"order" => $new_order,
"opts" => array(
"href" => $component_url . "/index.php",
)
));
}
////////////////////////////////////////////////////////////////////////
// CONFIGURATION FUNCTION
////////////////////////////////////////////////////////////////////////
function priorityobjects_component_config_func($mode, $inargs, &$outargs, &$result)
{
global $priorityobjects_component_name;
$result = 0;
$output = "";
switch ($mode) {
case COMPONENT_CONFIGMODE_GETSETTINGSHTML:
$settings_raw = get_option("priorityobjects_component_options");
if ($settings_raw == "") {
$settings = array(
'impact_var' => '_impact',
'urgency_var' => '_urgency',
'min_priority' => 1,
'object_type' => 'both',
'show_nested' => false,
'max_results' => 500,
'records_per_page' => 50,
'refresh_interval' => 30
);
} else {
$settings = unserialize($settings_raw);
}
$impact_var = grab_array_var($settings, "impact_var", "_impact");
$urgency_var = grab_array_var($settings, "urgency_var", "_urgency");
$min_priority = grab_array_var($settings, "min_priority", 1);
$object_type = grab_array_var($settings, "object_type", "both");
$show_nested = grab_array_var($settings, "show_nested", false);
$max_results = grab_array_var($settings, "max_results", 500);
$records_per_page = grab_array_var($settings, "records_per_page", 50);
$refresh_interval = grab_array_var($settings, "refresh_interval", 30);
ob_start();
?>
<p class="text-muted"><?php echo _("Priority is calculated using ServiceNow's impact/urgency matrix from custom variables."); ?></p>
<div class="form-group">
<label><?php echo _("Impact Custom Variable Name"); ?></label>
<input type="text" class="form-control" name="impact_var" value="<?php echo encode_form_val($impact_var); ?>" placeholder="_impact">
<small class="text-muted"><?php echo _("Custom variable name for impact (1-4 scale)"); ?></small>
</div>
<div class="form-group">
<label><?php echo _("Urgency Custom Variable Name"); ?></label>
<input type="text" class="form-control" name="urgency_var" value="<?php echo encode_form_val($urgency_var); ?>" placeholder="_urgency">
<small class="text-muted"><?php echo _("Custom variable name for urgency (1-4 scale)"); ?></small>
</div>
<div class="form-group">
<label><?php echo _("Minimum Priority to Display"); ?></label>
<select name="min_priority" class="form-control">
<option value="1" <?php echo is_selected($min_priority, 1); ?>><?php echo _("Priority 1 (Critical)"); ?></option>
<option value="2" <?php echo is_selected($min_priority, 2); ?>><?php echo _("Priority 2 (High)"); ?></option>
<option value="3" <?php echo is_selected($min_priority, 3); ?>><?php echo _("Priority 3 (Medium)"); ?></option>
<option value="4" <?php echo is_selected($min_priority, 4); ?>><?php echo _("Priority 4 (Low)"); ?></option>
</select>
</div>
<div class="form-group">
<label><?php echo _("Object Type"); ?></label>
<select name="object_type" class="form-control">
<option value="both" <?php echo is_selected($object_type, "both"); ?>><?php echo _("Both Hosts and Services"); ?></option>
<option value="hosts" <?php echo is_selected($object_type, "hosts"); ?>><?php echo _("Hosts Only"); ?></option>
<option value="services" <?php echo is_selected($object_type, "services"); ?>><?php echo _("Services Only"); ?></option>
</select>
</div>
<div class="form-group">
<label>
<input type="checkbox" name="show_nested" value="1" <?php echo is_checked($show_nested, true); ?>>
<?php echo _("Show services nested under hosts"); ?>
</label>
</div>
<div class="form-group">
<label><?php echo _("Maximum Results"); ?></label>
<input type="number" class="form-control" name="max_results" value="<?php echo intval($max_results); ?>" min="100" max="5000" step="100" style="width: 150px;">
</div>
<div class="form-group">
<label><?php echo _("Records Per Page"); ?></label>
<select name="records_per_page" class="form-control">
<option value="10" <?php echo is_selected($records_per_page, 10); ?>>10</option>
<option value="25" <?php echo is_selected($records_per_page, 25); ?>>25</option>
<option value="50" <?php echo is_selected($records_per_page, 50); ?>>50</option>
<option value="100" <?php echo is_selected($records_per_page, 100); ?>>100</option>
<option value="200" <?php echo is_selected($records_per_page, 200); ?>>200</option>
</select>
</div>
<div class="form-group">
<label><?php echo _("Auto-Refresh Interval (seconds)"); ?></label>
<select name="refresh_interval" class="form-control">
<option value="0" <?php echo is_selected($refresh_interval, 0); ?>><?php echo _("Disabled"); ?></option>
<option value="10" <?php echo is_selected($refresh_interval, 10); ?>>10</option>
<option value="15" <?php echo is_selected($refresh_interval, 15); ?>>15</option>
<option value="30" <?php echo is_selected($refresh_interval, 30); ?>>30</option>
<option value="60" <?php echo is_selected($refresh_interval, 60); ?>>60</option>
<option value="120" <?php echo is_selected($refresh_interval, 120); ?>>120</option>
</select>
</div>
<?php
$output = ob_get_clean();
break;
case COMPONENT_CONFIGMODE_SAVESETTINGS:
$settings = array(
'impact_var' => grab_request_var('impact_var', '_impact'),
'urgency_var' => grab_request_var('urgency_var', '_urgency'),
'min_priority' => intval(grab_request_var('min_priority', 1)),
'object_type' => grab_request_var('object_type', 'both'),
'show_nested' => grab_request_var('show_nested', 0) ? true : false,
'max_results' => intval(grab_request_var('max_results', 500)),
'records_per_page' => intval(grab_request_var('records_per_page', 50)),
'refresh_interval' => intval(grab_request_var('refresh_interval', 30))
);
set_option('priorityobjects_component_options', serialize($settings));
$outargs[COMPONENT_INFO_MESSAGES][] = _("Settings saved successfully.");
break;
default:
break;
}
return $output;
}