1<?php 2 3/** 4 * Observium Network Management and Monitoring System 5 * Copyright (C) 2006-2015, Adam Armstrong - http://www.observium.org 6 * 7 * @package observium 8 * @subpackage webui 9 * @author Adam Armstrong <adama@observium.org> 10 * @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited 11 * 12 */ 13 14// Contact display and editing page. 15 16if ($_SESSION['userlevel'] < 7) 17{ 18 // Allowed only secure global read permission 19 print_error_permission(); 20 return; 21} 22 23include($config['html_dir'].'/includes/alerting-navbar.inc.php'); 24 25include($config['html_dir'].'/includes/contacts-navbar.inc.php'); 26 27if ($contact = get_contact_by_id($vars['contact_id'])) 28{ 29 30?> 31 32<div class="row"> 33 <div class="col-sm-6"> 34<?php 35 36foreach (json_decode($contact['contact_endpoint']) as $field => $value) 37{ 38 $contact['endpoint_parameters'][$field] = $value; 39} 40 41$data = $config['transports'][$contact['contact_method']]; 42if (!count($data['parameters']['global'])) { $data['parameters']['global'] = array(); } // Temporary until we separate "global" out. 43// Plan: add defaults for transport types to global settings, which we use by default, then be able to override the settings via this GUI 44// This needs supporting code in the transport to check for set variable and if not, use the global default 45 46 $form = array('type' => 'horizontal', 47 'id' => 'update_contact_status', 48 'title' => 'Contact Information', 49 'space' => '5px', 50 //'fieldset' => array('edit' => ''), 51 ); 52 $row = 0; 53 $form['row'][++$row]['contact_method'] = array( 54 'type' => 'html', 55 //'fieldset' => 'edit', 56 'name' => 'Transport Method', 57 'class' => 'label', 58 'div_style' => 'padding-top: 5px;', 59 'readonly' => $readonly, 60 'value' => $data['name']); 61 62 $docs_link = OBSERVIUM_URL . '/docs/alerting_transports/#' . str_replace(' ', '-', strtolower($data['name'])); 63 $form['row'][++$row]['contact_doc'] = array( 64 'type' => 'html', 65 'fieldset' => 'body', 66 'offset' => TRUE, 67 'html' => '<a id="contact_doc" href="' . $docs_link . '" target="_blank">See documentation for this Transport (new page)</a>'); 68 69 $form['row'][++$row]['contact_enabled'] = array( 70 'type' => 'switch', 71 //'fieldset' => 'edit', 72 'name' => 'Contact Status', 73 'size' => 'small', 74 'on-color' => 'success', 75 'off-color' => 'danger', 76 'on-text' => 'Enabled', 77 'off-text' => 'Disabled', 78 'readonly' => $readonly, 79 'value' => !$contact['contact_disabled']); 80 81 $form['row'][++$row]['contact_descr'] = array( 82 'type' => 'text', 83 //'fieldset' => 'edit', 84 'name' => 'Description', 85 'width' => '80%', 86 'readonly' => $readonly, 87 'value' => $contact['contact_descr']); 88 89 if (count($data['parameters']['required']) || count($data['parameters']['global'])) 90 { 91 // Pseudo item, just for additional title 92 $form['row'][++$row]['contact_required'] = array( 93 'type' => 'html', 94 //'fieldset' => 'edit', 95 'html' => '<h3 id="contact_required">Required parameters</h3>'); 96 97 foreach (array_merge($data['parameters']['required'], $data['parameters']['global']) as $parameter => $param_data) // Temporary merge req & global 98 { 99 $form['row'][++$row]['contact_endpoint_'.$parameter] = array( 100 'type' => 'text', 101 //'fieldset' => 'edit', 102 'width' => '80%', 103 'name' => $param_data['description'], 104 'readonly' => $readonly, 105 'value' => $contact['endpoint_parameters'][$parameter]); 106 107 108 if (isset($param_data['tooltip'])) 109 { 110 $form['row'][$row]['tooltip_'.$parameter] = array( 111 'type' => 'raw', 112 //'fieldset' => 'edit', 113 'readonly' => $readonly, 114 'html' => generate_tooltip_link(NULL, '<i class="'.$config['icon']['question'].'"></i>', $param_data['tooltip'])); 115 } 116 117 } 118 } 119 120 if (count($data['parameters']['optional'])) 121 { 122 // Pseudo item, just for additional title 123 $form['row'][++$row]['contact_optional'] = array( 124 'type' => 'html', 125 //'fieldset' => 'edit', 126 'html' => '<h3 id="contact_optional">Optional parameters</h3>'); 127 128 foreach ($data['parameters']['optional'] as $parameter => $param_data) 129 { 130 $form['row'][++$row]['contact_endpoint_'.$parameter] = array( 131 'type' => 'text', 132 //'fieldset' => 'edit', 133 'width' => '80%', 134 'name' => $param_data['description'], 135 'readonly' => $readonly, 136 'value' => $contact['endpoint_parameters'][$parameter]); 137 138 139 if (isset($param_data['tooltip'])) 140 { 141 $form['row'][$row]['tooltip_'.$parameter] = array( 142 'type' => 'raw', 143 //'fieldset' => 'edit', 144 'readonly' => $readonly, 145 'html' => generate_tooltip_link(NULL, '<i class="'.$config['icon']['question'].'"></i>', $param_data['tooltip'])); 146 } 147 148 } 149 } 150 151 $form['row'][++$row]['submit'] = array( 152 'type' => 'submit', 153 'name' => 'Save Changes', 154 'icon' => 'icon-ok icon-white', 155 'right' => TRUE, 156 'class' => 'btn-primary', 157 'readonly' => $readonly, 158 'value' => 'update-contact-entry'); 159 160 //print_vars($form); 161 print_form($form); 162 unset($form, $row); 163?> 164 165 </div> 166 167 <div class="col-sm-6"> 168 169<?php 170 171 // Alert associations 172 $assoc_exists = array(); 173 $assocs = dbFetchRows('SELECT * FROM `alert_contacts_assoc` AS A 174 LEFT JOIN `alert_tests` AS T ON T.`alert_test_id` = A.`alert_checker_id` 175 WHERE `aca_type` = ? AND `contact_id` = ? 176 ORDER BY `entity_type`, `alert_name` DESC', array('alert', $contact['contact_id'])); 177 //r($assocs); 178 echo generate_box_open(array('title' => 'Associated Alert Checkers', 'header-border' => TRUE)); 179 if (count($assocs)) 180 { 181 182 echo('<table class="'. OBS_CLASS_TABLE_STRIPED .'">'); 183 184 foreach ($assocs as $assoc) 185 { 186 187 $alert_test = get_alert_test_by_id($assoc['alert_checker_id']); 188 189 $assoc_exists[$assoc['alert_checker_id']] = TRUE; 190 191 echo('<tr> 192 <td width="150px"><i class="'.$config['entities'][$alert_test['entity_type']]['icon'].'"></i> '.nicecase($alert_test['entity_type']).'</td> 193 <td>'.escape_html($alert_test['alert_name']).'</td> 194 <td width="25px">'); 195 196 $form = array('type' => 'simple', 197 //'userlevel' => 10, // Minimum user level for display form 198 'id' => 'delete_alert_checker_'.$assoc['alert_checker_id'], 199 'style' => 'display:inline;', 200 ); 201 $form['row'][0]['alert_test_id'] = array( 202 'type' => 'hidden', 203 'value' => $assoc['alert_checker_id']); 204 $form['row'][0]['contact_id'] = array( 205 'type' => 'hidden', 206 'value' => $contact['contact_id']); 207 208 $form['row'][99]['action'] = array( 209 'type' => 'submit', 210 'icon_only' => TRUE, // hide button styles 211 'name' => '', 212 'icon' => $config['icon']['cancel'], 213 //'right' => TRUE, 214 //'class' => 'btn-small', 215 // confirmation dialog 216 'attribs' => array('data-toggle' => 'confirm', // Enable confirmation dialog 217 'data-confirm-placement' => 'left', 218 'data-confirm-content' => 'Delete associated checker "'.escape_html($alert_test['alert_name']).'"?', 219 //'data-confirm-content' => '<div class="alert alert-warning"><h4 class="alert-heading"><i class="icon-warning-sign"></i> Warning!</h4> 220 // This association will be deleted!</div>'), 221 ), 222 'value' => 'delete_alert_checker_contact'); 223 224 print_form($form); 225 unset($form); 226 227 echo('</td> 228 </tr>'); 229 } 230 231 echo('</table>'); 232 233 } else { 234 echo('<p class="text-center text-warning bg-warning" style="padding: 10px; margin: 0px;"><strong>This contact is not currently associated with any Alert Checkers</strong></p>'); 235 } 236 237 // FIXME -- use NOT IN to mask already associated things. 238 239 $alert_tests = dbFetchRows('SELECT * FROM `alert_tests` ORDER BY `entity_type`, `alert_name`'); 240 241 if (count($alert_tests)) 242 { 243 foreach ($alert_tests as $alert_test) 244 { 245 if (!isset($assoc_exists[$alert_test['alert_test_id']])) 246 { 247 $form_items['alert_checker_id'][$alert_test['alert_test_id']] = array('name' => escape_html($alert_test['alert_name']), 248 'icon' => $config['entities'][$alert_test['entity_type']]['icon']); 249 } 250 } 251 252 $form = array('type' => 'simple', 253 //'userlevel' => 10, // Minimum user level for display form 254 'id' => 'associate_alert_check', 255 'style' => 'padding: 7px; margin: 0px;', 256 'right' => TRUE, 257 ); 258 $form['row'][0]['type'] = array( 259 'type' => 'hidden', 260 'value' => 'alert'); 261 $form['row'][0]['alert_checker_id'] = array( 262 'type' => 'select', 263 'name' => 'Associate Alert Checker', 264 'live-search' => FALSE, 265 'width' => '250px', 266 //'right' => TRUE, 267 'readonly' => $readonly, 268 'values' => $form_items['alert_checker_id'], 269 'value' => $vars['alert_checker_id']); 270 $form['row'][0]['action'] = array( 271 'type' => 'submit', 272 'name' => 'Associate', 273 'icon' => $config['icon']['plus'], 274 //'right' => TRUE, 275 'readonly' => $readonly, 276 'class' => 'btn-primary', 277 'value' => 'associate_alert_check'); 278 279 $box_close['footer_content'] = generate_form($form); 280 $box_close['footer_nopadding'] = TRUE; 281 unset($form, $form_items); 282 283 } else { 284 // print_warning('No unassociated alert checkers.'); 285 } 286 287 echo generate_box_close($box_close); 288 289 // Syslog associations 290 $assoc_exists = array(); 291 $assocs = dbFetchRows('SELECT * FROM `alert_contacts_assoc` AS A 292 LEFT JOIN `syslog_rules` AS T ON T.`la_id` = A.`alert_checker_id` 293 WHERE `aca_type` = ? AND `contact_id` = ? 294 ORDER BY `la_severity`, `la_name` DESC', array('syslog', $contact['contact_id'])); 295 //r($assocs); 296 echo generate_box_open(array('title' => 'Associated Syslog Rules', 'header-border' => TRUE)); 297 if (count($assocs)) 298 { 299 300 echo('<table class="'. OBS_CLASS_TABLE_STRIPED .'">'); 301 302 foreach ($assocs as $assoc) 303 { 304 305 //$alert_test = get_alert_test_by_id($assoc['alert_checker_id']); 306 307 $assoc_exists[$assoc['la_id']] = TRUE; 308 309 echo('<tr> 310 <td width="150"><i class="'.$config['icon']['syslog-alerts'].'"></i> '.escape_html($assoc['la_name']).'</td> 311 <td>'.escape_html($assoc['la_rule']).'</td> 312 <td width="25">'); 313 314 $form = array('type' => 'simple', 315 //'userlevel' => 10, // Minimum user level for display form 316 'id' => 'delete_syslog_checker_'.$assoc['la_id'], 317 'style' => 'display:inline;', 318 ); 319 $form['row'][0]['alert_test_id'] = array( 320 'type' => 'hidden', 321 'value' => $assoc['la_id']); 322 $form['row'][0]['contact_id'] = array( 323 'type' => 'hidden', 324 'value' => $contact['contact_id']); 325 326 $form['row'][99]['action'] = array( 327 //$form['row'][99]['submit'] = array( 328 'type' => 'submit', 329 'icon_only' => TRUE, // hide button styles 330 'name' => '', 331 'icon' => $config['icon']['cancel'], 332 //'right' => TRUE, 333 //'class' => 'btn-small', 334 // confirmation dialog 335 'attribs' => array('data-toggle' => 'confirm', // Enable confirmation dialog 336 'data-confirm-placement' => 'left', 337 'data-confirm-content' => 'Delete associated rule "'.escape_html($assoc['la_name']).'"?', 338 //'data-confirm-content' => '<div class="alert alert-warning"><h4 class="alert-heading"><i class="icon-warning-sign"></i> Warning!</h4> 339 // This association will be deleted!</div>'), 340 ), 341 'value' => 'delete_syslog_checker_contact'); 342 343 print_form($form); 344 unset($form); 345 346 echo('</td> 347 </tr>'); 348 349 } 350 351 echo('</table>'); 352 353 } else { 354 echo('<p class="text-center text-warning bg-warning" style="padding: 10px; margin: 0px;"><strong>This contact is not currently associated with any Syslog Rules</strong></p>'); 355 } 356 357 $alert_tests = dbFetchRows('SELECT * FROM `syslog_rules` ORDER BY `la_severity`, `la_name`'); 358 359 if (count($alert_tests)) 360 { 361 foreach ($alert_tests as $alert_test) 362 { 363 if (!isset($assoc_exists[$alert_test['la_id']])) 364 { 365 $form_items['la_id'][$alert_test['la_id']] = array('name' => escape_html($alert_test['la_name']), 366 'subtext' => escape_html($alert_test['la_rule']), 367 'icon' => $config['icon']['syslog-alerts']); 368 } 369 } 370 371 $form = array('type' => 'simple', 372 //'userlevel' => 10, // Minimum user level for display form 373 'id' => 'associate_syslog_rule', 374 'style' => 'padding: 7px; margin: 0px;', 375 'right' => TRUE, 376 ); 377 $form['row'][0]['type'] = array( 378 'type' => 'hidden', 379 'value' => 'syslog'); 380 $form['row'][0]['la_id'] = array( 381 'type' => 'select', 382 'name' => 'Associate Syslog Rule', 383 'live-search' => FALSE, 384 'width' => '250px', 385 //'right' => TRUE, 386 'readonly' => $readonly, 387 'values' => $form_items['la_id'], 388 'value' => $vars['la_id']); 389 $form['row'][0]['action'] = array( 390 'type' => 'submit', 391 'name' => 'Associate', 392 'icon' => $config['icon']['plus'], 393 //'right' => TRUE, 394 'readonly' => $readonly, 395 'class' => 'btn-primary', 396 'value' => 'associate_syslog_rule'); 397 398 $box_close['footer_content'] = generate_form($form); 399 $box_close['footer_nopadding'] = TRUE; 400 unset($form, $form_items); 401 402 } else { 403 // print_warning('No unassociated syslog rules.'); 404 } 405 406 echo generate_box_close($box_close); 407 408 echo('</div>'); 409} else { 410 print_error("Contact doesn't exist."); 411} 412 413// EOF 414