mirror of
				https://github.com/librenms/librenms.git
				synced 2024-10-07 16:52:45 +00:00 
			
		
		
		
	Merge pull request #3568 from gcoeugnet/master
Add procedure management from alerting widget
This commit is contained in:
		| @@ -4,6 +4,7 @@ Table of Content: | ||||
| - [Rules](#rules) | ||||
|     - [Syntax](#rules-syntax) | ||||
|     - [Examples](#rules-examples) | ||||
|     - [Procedure](#rules-procedure) | ||||
| - [Templates](#templates) | ||||
|     - [Syntax](#templates-syntax) | ||||
|     - [Examples](#templates-examples) | ||||
| @@ -89,6 +90,9 @@ Alert when: | ||||
| - High CPU usage(per core usage, not overall): `%macros.device_up = "1" && %processors.processor_usage >= "90"` | ||||
| - High port usage, where description is not client & ifType is not softwareLoopback: `%macros.port_usage_perc >= "80" && %port.port_descr_type != "client" && %ports.ifType != "softwareLoopback"` | ||||
|  | ||||
| ## <a name="rules-procedure">Procedure</a> | ||||
| You can associate a rule to a procedure by giving the URL of the procedure when creating the rule. Only links like "http://" are supported, otherwise an error will be returned. Once configured, procedure can be opened from the Alert widget through the "Open" button, which can be shown/hidden from the widget configuration box. | ||||
|  | ||||
| # <a name="templates">Templates</a> | ||||
|  | ||||
| Templates can be assigned to a single or a group of rules. | ||||
|   | ||||
| @@ -26,6 +26,7 @@ if(defined('show_settings')) { | ||||
|     $current_severity     = isset($widget_settings['severity']) ? $widget_settings['severity'] : ''; | ||||
|     $current_state        = isset($widget_settings['state']) ? $widget_settings['state'] : ''; | ||||
|     $current_group        = isset($widget_settings['group']) ? $widget_settings['group'] : ''; | ||||
|     $current_proc         = isset($widget_settings['proc']) ? $widget_settings['proc'] : ''; | ||||
|  | ||||
|     $common_output[] = ' | ||||
| <form class="form" onsubmit="widget_settings(this); return false;"> | ||||
| @@ -94,6 +95,20 @@ if(defined('show_settings')) { | ||||
|       </select> | ||||
|     </div> | ||||
|   </div> | ||||
|   <div class="form-group row"> | ||||
|     <div class="col-sm-4"> | ||||
|       <label for="proc" class="control-label">Show Procedure field: </label> | ||||
|     </div> | ||||
|     <div class="col-sm-8"> | ||||
|       <select class="form-control" name="proc">'; | ||||
|  | ||||
|     $common_output[] = '<option value="1"'.($current_proc == '1' ? ' selected' : ' ').'>show</option>'; | ||||
|     $common_output[] = '<option value="0"'.($current_proc == '0' ? ' selected' : ' ').'>hide</option>'; | ||||
|  | ||||
|     $common_output[] = ' | ||||
|       </select> | ||||
|     </div> | ||||
|   </div> | ||||
|  | ||||
|   <div class="form-group"> | ||||
|     <div class="col-sm-12"> | ||||
| @@ -109,6 +124,7 @@ else { | ||||
|     $state        = $widget_settings['state']; | ||||
|     $min_severity = $widget_settings['min_severity']; | ||||
|     $group        = $widget_settings['group']; | ||||
|     $proc         = $widget_settings['proc']; | ||||
|  | ||||
|     $title = "Alerts"; | ||||
|  | ||||
| @@ -165,7 +181,12 @@ else { | ||||
|                 <th data-column-id="hostname">Hostname</th> | ||||
|                 <th data-column-id="timestamp">Timestamp</th> | ||||
|                 <th data-column-id="severity">Severity</th> | ||||
|                 <th data-column-id="ack" data-formatter="ack" data-sortable="false">Acknowledge</th> | ||||
|                 <th data-column-id="ack" data-formatter="ack" data-sortable="false">Acknowledge</th>'; | ||||
|     if (is_numeric($proc)) { | ||||
|         if ($proc) { $common_output[] = '<th data-column-id="proc" data-formatter="proc" data-sortable="false">Procedure</th>'; } | ||||
|     } | ||||
|     else { $common_output[] = '<th data-column-id="proc" data-formatter="proc" data-sortable="false">Procedure</th>'; } | ||||
|     $common_output[] = ' | ||||
|             </tr> | ||||
|         </thead> | ||||
|     </table> | ||||
| @@ -192,6 +213,9 @@ var alerts_grid = $("#alerts_'.$unique_id.'").bootgrid({ | ||||
|     if (is_numeric($group)) { | ||||
|         $common_output[]="group: '$group',\n"; | ||||
|     } | ||||
|     if (is_numeric($proc)) { | ||||
|         $common_output[]="proc: '$proc',\n"; | ||||
|     } | ||||
|  | ||||
|     $common_output[]=' | ||||
|             device_id: \'' . $device['device_id'] .'\' | ||||
| @@ -204,6 +228,9 @@ var alerts_grid = $("#alerts_'.$unique_id.'").bootgrid({ | ||||
|         }, | ||||
|         "ack": function(column,row) { | ||||
|             return "<button type=\'button\' class=\'btn btn-"+row.ack_col+" btn-sm command-ack-alert\' data-target=\'#ack-alert\' data-state=\'"+row.state+"\' data-alert_id=\'"+row.alert_id+"\' name=\'ack-alert\' id=\'ack-alert\' data-extra=\'"+row.extra+"\'><span class=\'glyphicon glyphicon-"+row.ack_ico+"\'aria-hidden=\'true\'></span></button>"; | ||||
|         }, | ||||
|         "proc": function(column,row) { | ||||
|             return "<button type=\'button\' class=\'btn command-open-proc\' data-alert_id=\'"+row.alert_id+"\' name=\'open-proc\' id=\'open-proc\'>Open</button>"; | ||||
|         } | ||||
|     }, | ||||
|     templates: { | ||||
| @@ -230,6 +257,22 @@ var alerts_grid = $("#alerts_'.$unique_id.'").bootgrid({ | ||||
|         } | ||||
|       }); | ||||
|     }); | ||||
|     alerts_grid.find(".command-open-proc").on("click", function(e) { | ||||
|         e.preventDefault(); | ||||
|         var alert_id = $(this).data("alert_id"); | ||||
|         $.ajax({ | ||||
|             type: "POST", | ||||
|             url: "ajax_form.php", | ||||
|             data: { type: "open-proc", alert_id: alert_id }, | ||||
|             success: function(msg){ | ||||
| 	        if (msg != "ERROR") { window.open(msg); } | ||||
|                 else { $("#message").html(\'<div class="alert alert-info">Procedure link does not seem to be valid, please check the rule.</div>\'); } | ||||
|             }, | ||||
|             error: function(){ | ||||
|                  $("#message").html(\'<div class="alert alert-info">An error occurred opening procedure for this alert. Does the procedure link was configured  ?</div>\'); | ||||
|             } | ||||
|         }); | ||||
|     }); | ||||
|     alerts_grid.find(".command-ack-alert").on("click", function(e) { | ||||
|         e.preventDefault(); | ||||
|         var alert_id = $(this).data("alert_id"); | ||||
|   | ||||
| @@ -26,6 +26,8 @@ $interval = mres($_POST['interval']); | ||||
| $mute     = mres($_POST['mute']); | ||||
| $invert   = mres($_POST['invert']); | ||||
| $name     = mres($_POST['name']); | ||||
| if ($_POST['proc'] != "") { $proc = $_POST['proc']; } | ||||
| else { $proc = ""; } | ||||
|  | ||||
| if (empty($rule)) { | ||||
|     $update_message = 'ERROR: No rule was generated - did you forget to click and / or?'; | ||||
| @@ -61,7 +63,7 @@ else if (validate_device_id($_POST['device_id']) || $_POST['device_id'] == '-1' | ||||
|     ); | ||||
|     $extra_json = json_encode($extra); | ||||
|     if (is_numeric($alert_id) && $alert_id > 0) { | ||||
|         if (dbUpdate(array('rule' => $rule, 'severity' => mres($_POST['severity']), 'extra' => $extra_json, 'name' => $name), 'alert_rules', 'id=?', array($alert_id)) >= 0) { | ||||
|         if (dbUpdate(array('rule' => $rule, 'severity' => mres($_POST['severity']), 'extra' => $extra_json, 'name' => $name, 'proc' => $proc), 'alert_rules', 'id=?', array($alert_id)) >= 0) { | ||||
|             $update_message = "Edited Rule: <i>$name: $rule</i>"; | ||||
|         } | ||||
|         else { | ||||
| @@ -73,7 +75,7 @@ else if (validate_device_id($_POST['device_id']) || $_POST['device_id'] == '-1' | ||||
|             $device_id = ':'.$device_id; | ||||
|         } | ||||
|  | ||||
|         if (dbInsert(array('device_id' => $device_id, 'rule' => $rule, 'severity' => mres($_POST['severity']), 'extra' => $extra_json, 'disabled' => 0, 'name' => $name), 'alert_rules')) { | ||||
|         if (dbInsert(array('device_id' => $device_id, 'rule' => $rule, 'severity' => mres($_POST['severity']), 'extra' => $extra_json, 'disabled' => 0, 'name' => $name, 'proc' => $proc), 'alert_rules')) { | ||||
|             $update_message = "Added Rule: <i>$name: $rule</i>"; | ||||
|             if (is_array($_POST['maps'])) { | ||||
|                 foreach ($_POST['maps'] as $target) { | ||||
|   | ||||
							
								
								
									
										27
									
								
								html/includes/forms/open-proc.inc.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								html/includes/forms/open-proc.inc.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | ||||
| <?php | ||||
|  | ||||
| /* | ||||
|  * LibreNMS | ||||
|  * | ||||
|  * Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk/fa> | ||||
|  * | ||||
|  * This program is free software: you can redistribute it and/or modify it | ||||
|  * under the terms of the GNU General Public License as published by the | ||||
|  * Free Software Foundation, either version 3 of the License, or (at your | ||||
|  * option) any later version.  Please see LICENSE.txt at the top level of | ||||
|  * the source code distribution for details. | ||||
|  */ | ||||
| # header('Content-type: text/plain'); | ||||
|  | ||||
| $alert_id = $_POST['alert_id']; | ||||
| if (!is_numeric($alert_id)) { | ||||
|     echo 'ERROR: No alert selected'; | ||||
|     exit; | ||||
| } | ||||
| else { | ||||
|     $proc = dbFetchCell('SELECT proc FROM alerts,alert_rules WHERE alert_rules.id = alerts.rule_id AND alerts.id = ?', array($alert_id)); | ||||
|     if (($proc == "") || ($proc == "NULL")) { echo header("HTTP/1.0 404 Not Found"); } | ||||
|     else if (! preg_match ('/^http:\/\//', $proc)) { echo "ERROR"; } | ||||
|     else { echo $proc; } | ||||
|     exit; | ||||
| } | ||||
| @@ -28,6 +28,7 @@ if (is_numeric($alert_id) && $alert_id > 0) { | ||||
|         'severity' => $rule['severity'], | ||||
|         'extra'    => $rule['extra'], | ||||
|         'name'     => $rule['name'], | ||||
|         'proc'     => $rule['proc'], | ||||
|         'rules'    => $rule_split, | ||||
|     ); | ||||
| 	header('Content-type: application/json'); | ||||
|   | ||||
| @@ -134,6 +134,12 @@ if(is_admin() !== false) { | ||||
|                 </div> | ||||
|             </div> | ||||
|         </div> | ||||
|         <div class='form-group'> | ||||
|             <label for='proc' class='col-sm-3 control-label'>Procedure URL: </label> | ||||
|             <div class='col-sm-9'> | ||||
|                 <input type='text' id='proc' name='proc' class='form-control' maxlength='30'> | ||||
|             </div> | ||||
|         </div> | ||||
|         <div class="form-group"> | ||||
|                 <div class="col-sm-offset-3 col-sm-3"> | ||||
|                         <button class="btn btn-success btn-sm" type="submit" name="rule-submit" id="rule-submit" value="save">Save Rule</button> | ||||
| @@ -219,6 +225,7 @@ $('#create-alert').on('show.bs.modal', function (event) { | ||||
|             $("[name='mute']").bootstrapSwitch('state',extra['mute']); | ||||
|             $("[name='invert']").bootstrapSwitch('state',extra['invert']); | ||||
|             $('#name').val(output['name']); | ||||
|             $('#proc').val(output['proc']); | ||||
|         } | ||||
|     }); | ||||
| }); | ||||
|   | ||||
							
								
								
									
										1
									
								
								sql-schema/117.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								sql-schema/117.sql
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | ||||
| ALTER TABLE alert_rules ADD COLUMN proc VARCHAR(80) AFTER name; | ||||
		Reference in New Issue
	
	Block a user