Added ability to name alert rules

This commit is contained in:
Neil Lathwood
2014-12-21 15:44:50 +00:00
parent e867d3f1df
commit 51616844bc
5 changed files with 19 additions and 7 deletions

View File

@ -23,6 +23,7 @@ $alert_id = $_POST['alert_id'];
$count = mres($_POST['count']);
$delay = mres($_POST['delay']);
$mute = mres($_POST['mute']);
$name = mres($_POST['name']);
if(empty($rule)) {
$update_message = "ERROR: No rule was generated";
@ -40,14 +41,14 @@ if(empty($rule)) {
$extra = array('mute'=>$mute,'count'=>$count,'delay'=>$delay_sec);
$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), 'alert_rules', 'id=?',array($alert_id)) >= 0) {
$update_message = "Edited Rule: <i>".$rule."</i>";
if(dbUpdate(array('rule' => $rule,'severity'=>mres($_POST['severity']),'extra'=>$extra_json,'name'=>$name), 'alert_rules', 'id=?',array($alert_id)) >= 0) {
$update_message = "Edited Rule: <i>$name: $rule</i>";
} else {
$update_message = "ERROR: Failed to edit Rule: <i>".$rule."</i>";
}
} else {
if( dbInsert(array('device_id'=>$device_id,'rule'=>$rule,'severity'=>mres($_POST['severity']),'extra'=>$extra_json),'alert_rules') ) {
$update_message = "Added Rule: <i>".$rule.$mute."</i>";
if( dbInsert(array('device_id'=>$device_id,'rule'=>$rule,'severity'=>mres($_POST['severity']),'extra'=>$extra_json,'name'=>$name),'alert_rules') ) {
$update_message = "Added Rule: <i>$name: $rule</i>";
} else {
$update_message = "ERROR: Failed to add Rule: <i>".$rule."</i>";
}

View File

@ -23,6 +23,6 @@ if(is_numeric($alert_id) && $alert_id > 0) {
$rule_split = preg_split('/([a-zA-Z0-9_\-\.\=\%\ \"\'\!\~]+[&&||]+)/',$rule['rule'], -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
$count = count($rule_split) - 1;
$rule_split[$count] = $rule_split[$count].'&&';
$output = array('severity'=>$rule['severity'],'extra'=>$rule['extra'],'rules'=>$rule_split);
$output = array('severity'=>$rule['severity'],'extra'=>$rule['extra'],'name'=>$rule['name'],'rules'=>$rule_split);
echo _json_encode($output);
}

View File

@ -100,6 +100,12 @@ if(is_admin() === false) {
<input type="checkbox" name="mute" id="mute">
</div>
</div>
<div class='form-group'>
<label for='name' class='col-sm-3 control-label'>Rule name: </label>
<div class='col-sm-9'>
<input type='text' id='name' name='name' class='form-control' maxlength='200'>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-3">
<button class="btn btn-default btn-sm" type="submit" name="rule-submit" id="rule-submit" value="save">Save Rule</button>
@ -157,6 +163,7 @@ $('#create-alert').on('show.bs.modal', function (event) {
if(extra['mute']) {
$('#mute').click();
}
$('#name').val(output['name']);
}
});
});

View File

@ -22,6 +22,7 @@ echo '<div class="table-responsive">
<table class="table table-hover table-condensed" width="100%">
<tr>
<th>#</th>
<th>Name</th>
<th>Rule</th>
<th>Severity</th>
<th>Status</th>
@ -30,7 +31,7 @@ echo '<div class="table-responsive">
<th>Action</th>
</tr>';
echo ('<td colspan="6">');
echo ('<td colspan="7">');
if ($_SESSION['userlevel'] == '10') {
echo('<button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#create-alert" data-device_id="'. $device['device_id'] .'">Create new alert rule</button>');
}
@ -100,6 +101,7 @@ foreach( dbFetchRows($full_query, $param) as $rule ) {
$rule_extra = json_decode($rule['extra'],TRUE);
echo "<tr class='".$extra."' id='row_".$rule['id']."'>";
echo "<td><i>#".((int) $rulei++)."</i></td>";
echo "<td>".$rule['name']."</td>";
echo "<td><i>".htmlentities($rule['rule'])."</i></td>";
echo "<td>".$rule['severity']."</td>";
echo "<td><span id='alert-rule-".$rule['id']."' class='glyphicon glyphicon-".$ico." glyphicon-large text-".$col."'></span> ";
@ -122,7 +124,7 @@ foreach( dbFetchRows($full_query, $param) as $rule ) {
}
if($count % $results > 0) {
echo(' <tr>
<td colspan="7" align="center">'. generate_pagination($count,$results,$page_number) .'</td>
<td colspan="8" align="center">'. generate_pagination($count,$results,$page_number) .'</td>
</tr>');
}
echo '</table>

2
sql-schema/037.sql Normal file
View File

@ -0,0 +1,2 @@
-- Adds name column to alert_rules table
ALTER TABLE `alert_rules` ADD `name` VARCHAR( 255 ) NOT NULL ;