librenms-librenms/includes/html/print-alert-rules.php

548 lines
22 KiB
PHP
Raw Normal View History

<?php
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
/**
* print-alert-rules.inc.php
*
* LibreNMS print alert rules table
*
* 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2020 The LibreNMS Community
* @author Original Author <unknown>
* @author Joseph Tingiris <joseph.tingiris@gmail.com>
*/
if (!Auth::user()->hasGlobalAdmin()) {
die('ERROR: You need to be admin');
}
feature: Added new alert rule builder UI and rule mapping UI (#8293) * feature: Added new alert rule builder UI * Updated to export sql queries * More updates * more changes * removed debug * fix scrut * Updated to include import options + various other fixes * fix rule * Populate name from collection rules. * Fix default rule import Allow new and old style rules in the collection. Don't add new yet as I'm not sure GenSQL() is working. * Fix GenSQL call * Extract filter building to class so it is nicely contained in one place * moved schema * some fixes and tweaks * travis fixes * Some more features / updates * Fix up my mistakes when adding default rules * Use a modal for new alert (Incomplete) Larger dialog!! Remove page loading stuff. Working: Loading rules, resetting dialog, importing from collection. Not working yet: select width device limited rule access? don't know what this is... Lots of unused stuff to delete... * reload "table" after save * fixed editing rule * Auto select2 width * Reload window on save * Restore per-device alert. Remove debug. * Small cleanups. Rule Name first. * Restore button to button type. Rename schema. * Fixes: wrong command to reload window, remove extra attributes, rule is never passed * Fixed old rule editing * some small updates for old imports * travis update to use trusty * maybe travis fix * Ability to set alert rule mappings on the rule edit screen * pip installs one line, no quiet for deploy * update schema def * Fix style and some copyright headers * fix docs missing file * Allow new versions of snmpsim and libraries * Parser WIP * Fix default rules insert * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * small rule collection fix * Working on glues * Working on glues * Docs updates + small UI changes * Parser WIP * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * Working on glues * Working on glues * Add table mapping, should move to it's own class * WIP * Glue working!! * Extract Schema class * Some final touches. revert alerts_rules.json for now. * Finish up initial implementation Needs more tests * Fix a few places * small doc updates * Fix finding tables in grouped rules. * remove unused code * code format fixes * Some quick tests for Schema Simplified output for findRelationshipPath. Always includes start and target in the result. This simplifies a lot of code in QueryBuilderParser.php This also always loads the target table data now (which we want) * Make bill_id the PRIMARY index for the bills table * Load macros from a json file in misc instead of the database. * Fix whitespace and wrong key for collection. * Handle IN properly when generating SQL * Fix glue (devices.device_id = ports.port_id) is incorrect :D Show ALL tables we can resolve relationships for in the query builder filter. * Remove all macros from the database Remove insert statements, leave updates to update user's existing rules.
2018-03-14 20:25:19 +00:00
use LibreNMS\Alerting\QueryBuilderParser;
2015-07-13 20:10:26 +02:00
$no_refresh = true;
?>
2014-11-30 17:49:52 +00:00
<div class="row">
<div class="col-sm-12">
<span id="message"></span>
</div>
</div>
<?php
2015-07-13 20:10:26 +02:00
if (isset($_POST['create-default'])) {
$default_rules = array_filter(get_rules_from_json(), function ($rule) {
return isset($rule['default']) && $rule['default'];
});
$default_extra = array(
'mute' => false,
'count' => -1,
'delay' => 300,
'invert' => false,
'interval' => 300,
2016-07-03 19:47:12 +01:00
);
2015-07-13 20:10:26 +02:00
foreach ($default_rules as $add_rule) {
$extra = $default_extra;
if (isset($add_rule['extra'])) {
$extra = array_replace($extra, json_decode($add_rule['extra'], true));
}
feature: Added new alert rule builder UI and rule mapping UI (#8293) * feature: Added new alert rule builder UI * Updated to export sql queries * More updates * more changes * removed debug * fix scrut * Updated to include import options + various other fixes * fix rule * Populate name from collection rules. * Fix default rule import Allow new and old style rules in the collection. Don't add new yet as I'm not sure GenSQL() is working. * Fix GenSQL call * Extract filter building to class so it is nicely contained in one place * moved schema * some fixes and tweaks * travis fixes * Some more features / updates * Fix up my mistakes when adding default rules * Use a modal for new alert (Incomplete) Larger dialog!! Remove page loading stuff. Working: Loading rules, resetting dialog, importing from collection. Not working yet: select width device limited rule access? don't know what this is... Lots of unused stuff to delete... * reload "table" after save * fixed editing rule * Auto select2 width * Reload window on save * Restore per-device alert. Remove debug. * Small cleanups. Rule Name first. * Restore button to button type. Rename schema. * Fixes: wrong command to reload window, remove extra attributes, rule is never passed * Fixed old rule editing * some small updates for old imports * travis update to use trusty * maybe travis fix * Ability to set alert rule mappings on the rule edit screen * pip installs one line, no quiet for deploy * update schema def * Fix style and some copyright headers * fix docs missing file * Allow new versions of snmpsim and libraries * Parser WIP * Fix default rules insert * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * small rule collection fix * Working on glues * Working on glues * Docs updates + small UI changes * Parser WIP * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * Working on glues * Working on glues * Add table mapping, should move to it's own class * WIP * Glue working!! * Extract Schema class * Some final touches. revert alerts_rules.json for now. * Finish up initial implementation Needs more tests * Fix a few places * small doc updates * Fix finding tables in grouped rules. * remove unused code * code format fixes * Some quick tests for Schema Simplified output for findRelationshipPath. Always includes start and target in the result. This simplifies a lot of code in QueryBuilderParser.php This also always loads the target table data now (which we want) * Make bill_id the PRIMARY index for the bills table * Load macros from a json file in misc instead of the database. * Fix whitespace and wrong key for collection. * Handle IN properly when generating SQL * Fix glue (devices.device_id = ports.port_id) is incorrect :D Show ALL tables we can resolve relationships for in the query builder filter. * Remove all macros from the database Remove insert statements, leave updates to update user's existing rules.
2018-03-14 20:25:19 +00:00
$qb = QueryBuilderParser::fromOld($add_rule['rule']);
$insert = array(
feature: Added new alert rule builder UI and rule mapping UI (#8293) * feature: Added new alert rule builder UI * Updated to export sql queries * More updates * more changes * removed debug * fix scrut * Updated to include import options + various other fixes * fix rule * Populate name from collection rules. * Fix default rule import Allow new and old style rules in the collection. Don't add new yet as I'm not sure GenSQL() is working. * Fix GenSQL call * Extract filter building to class so it is nicely contained in one place * moved schema * some fixes and tweaks * travis fixes * Some more features / updates * Fix up my mistakes when adding default rules * Use a modal for new alert (Incomplete) Larger dialog!! Remove page loading stuff. Working: Loading rules, resetting dialog, importing from collection. Not working yet: select width device limited rule access? don't know what this is... Lots of unused stuff to delete... * reload "table" after save * fixed editing rule * Auto select2 width * Reload window on save * Restore per-device alert. Remove debug. * Small cleanups. Rule Name first. * Restore button to button type. Rename schema. * Fixes: wrong command to reload window, remove extra attributes, rule is never passed * Fixed old rule editing * some small updates for old imports * travis update to use trusty * maybe travis fix * Ability to set alert rule mappings on the rule edit screen * pip installs one line, no quiet for deploy * update schema def * Fix style and some copyright headers * fix docs missing file * Allow new versions of snmpsim and libraries * Parser WIP * Fix default rules insert * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * small rule collection fix * Working on glues * Working on glues * Docs updates + small UI changes * Parser WIP * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * Working on glues * Working on glues * Add table mapping, should move to it's own class * WIP * Glue working!! * Extract Schema class * Some final touches. revert alerts_rules.json for now. * Finish up initial implementation Needs more tests * Fix a few places * small doc updates * Fix finding tables in grouped rules. * remove unused code * code format fixes * Some quick tests for Schema Simplified output for findRelationshipPath. Always includes start and target in the result. This simplifies a lot of code in QueryBuilderParser.php This also always loads the target table data now (which we want) * Make bill_id the PRIMARY index for the bills table * Load macros from a json file in misc instead of the database. * Fix whitespace and wrong key for collection. * Handle IN properly when generating SQL * Fix glue (devices.device_id = ports.port_id) is incorrect :D Show ALL tables we can resolve relationships for in the query builder filter. * Remove all macros from the database Remove insert statements, leave updates to update user's existing rules.
2018-03-14 20:25:19 +00:00
'rule' => '',
'builder' => json_encode($qb),
'query' => $qb->toSql(),
'severity' => 'critical',
'extra' => json_encode($extra),
'disabled' => 0,
'name' => $add_rule['name']
);
dbInsert($insert, 'alert_rules');
}
feature: Added new alert rule builder UI and rule mapping UI (#8293) * feature: Added new alert rule builder UI * Updated to export sql queries * More updates * more changes * removed debug * fix scrut * Updated to include import options + various other fixes * fix rule * Populate name from collection rules. * Fix default rule import Allow new and old style rules in the collection. Don't add new yet as I'm not sure GenSQL() is working. * Fix GenSQL call * Extract filter building to class so it is nicely contained in one place * moved schema * some fixes and tweaks * travis fixes * Some more features / updates * Fix up my mistakes when adding default rules * Use a modal for new alert (Incomplete) Larger dialog!! Remove page loading stuff. Working: Loading rules, resetting dialog, importing from collection. Not working yet: select width device limited rule access? don't know what this is... Lots of unused stuff to delete... * reload "table" after save * fixed editing rule * Auto select2 width * Reload window on save * Restore per-device alert. Remove debug. * Small cleanups. Rule Name first. * Restore button to button type. Rename schema. * Fixes: wrong command to reload window, remove extra attributes, rule is never passed * Fixed old rule editing * some small updates for old imports * travis update to use trusty * maybe travis fix * Ability to set alert rule mappings on the rule edit screen * pip installs one line, no quiet for deploy * update schema def * Fix style and some copyright headers * fix docs missing file * Allow new versions of snmpsim and libraries * Parser WIP * Fix default rules insert * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * small rule collection fix * Working on glues * Working on glues * Docs updates + small UI changes * Parser WIP * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * Working on glues * Working on glues * Add table mapping, should move to it's own class * WIP * Glue working!! * Extract Schema class * Some final touches. revert alerts_rules.json for now. * Finish up initial implementation Needs more tests * Fix a few places * small doc updates * Fix finding tables in grouped rules. * remove unused code * code format fixes * Some quick tests for Schema Simplified output for findRelationshipPath. Always includes start and target in the result. This simplifies a lot of code in QueryBuilderParser.php This also always loads the target table data now (which we want) * Make bill_id the PRIMARY index for the bills table * Load macros from a json file in misc instead of the database. * Fix whitespace and wrong key for collection. * Handle IN properly when generating SQL * Fix glue (devices.device_id = ports.port_id) is incorrect :D Show ALL tables we can resolve relationships for in the query builder filter. * Remove all macros from the database Remove insert statements, leave updates to update user's existing rules.
2018-03-14 20:25:19 +00:00
unset($qb);
}
2014-11-30 17:49:52 +00:00
require_once 'includes/html/modal/new_alert_rule.inc.php';
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
require_once 'includes/html/modal/delete_alert_rule.inc.php'; // Also dies if !Auth::user()->hasGlobalAdmin()
require_once 'includes/html/modal/alert_rule_collection.inc.php'; // Also dies if !Auth::user()->hasGlobalAdmin()
2020-02-26 15:07:48 +01:00
require_once 'includes/html/modal/alert_rule_list.inc.php'; // Also dies if !Auth::user()->hasGlobalAdmin()
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
require_once 'includes/html/modal/edit_transport_group.inc.php';
require_once 'includes/html/modal/edit_alert_transport.inc.php';
echo '<form method="post" action="" id="result_form">';
echo csrf_field();
2015-07-13 20:10:26 +02:00
if (isset($_POST['results_amount']) && $_POST['results_amount'] > 0) {
2014-11-30 17:49:52 +00:00
$results = $_POST['results'];
} else {
2014-11-30 17:49:52 +00:00
$results = 50;
}
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
echo '<div class="table-responsive">';
echo '<div class="col pull-left">';
echo '<button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#create-alert" data-device_id="'.$device['device_id'].'"><i class="fa fa-plus"></i> Create new alert rule</button>';
echo '<i> - OR - </i>';
echo '<button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#search_rule_modal" data-device_id="'.$device['device_id'].'"><i class="fa fa-plus"></i> Create rule from collection</button>';
echo '</div>';
echo '<div class="col pull-right">';
echo '<select data-toggle="popover" data-placement="left" data-content="results per page" name="results" id="results" class="form-control input-sm" onChange="updateResults(this);">';
2015-07-13 20:10:26 +02:00
$result_options = array(
'10',
'50',
'100',
'250',
'500',
'1000',
'5000',
);
foreach ($result_options as $option) {
2014-11-30 17:49:52 +00:00
echo "<option value='$option'";
2015-07-13 20:10:26 +02:00
if ($results == $option) {
echo ' selected';
2014-11-30 17:49:52 +00:00
}
echo ">$option</option>";
}
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
echo '</select>';
echo '</div>';
echo '</div>';
2015-07-13 20:10:26 +02:00
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
echo '<br>';
2015-07-13 20:10:26 +02:00
feature: Added new alert rule builder UI and rule mapping UI (#8293) * feature: Added new alert rule builder UI * Updated to export sql queries * More updates * more changes * removed debug * fix scrut * Updated to include import options + various other fixes * fix rule * Populate name from collection rules. * Fix default rule import Allow new and old style rules in the collection. Don't add new yet as I'm not sure GenSQL() is working. * Fix GenSQL call * Extract filter building to class so it is nicely contained in one place * moved schema * some fixes and tweaks * travis fixes * Some more features / updates * Fix up my mistakes when adding default rules * Use a modal for new alert (Incomplete) Larger dialog!! Remove page loading stuff. Working: Loading rules, resetting dialog, importing from collection. Not working yet: select width device limited rule access? don't know what this is... Lots of unused stuff to delete... * reload "table" after save * fixed editing rule * Auto select2 width * Reload window on save * Restore per-device alert. Remove debug. * Small cleanups. Rule Name first. * Restore button to button type. Rename schema. * Fixes: wrong command to reload window, remove extra attributes, rule is never passed * Fixed old rule editing * some small updates for old imports * travis update to use trusty * maybe travis fix * Ability to set alert rule mappings on the rule edit screen * pip installs one line, no quiet for deploy * update schema def * Fix style and some copyright headers * fix docs missing file * Allow new versions of snmpsim and libraries * Parser WIP * Fix default rules insert * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * small rule collection fix * Working on glues * Working on glues * Docs updates + small UI changes * Parser WIP * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * Working on glues * Working on glues * Add table mapping, should move to it's own class * WIP * Glue working!! * Extract Schema class * Some final touches. revert alerts_rules.json for now. * Finish up initial implementation Needs more tests * Fix a few places * small doc updates * Fix finding tables in grouped rules. * remove unused code * code format fixes * Some quick tests for Schema Simplified output for findRelationshipPath. Always includes start and target in the result. This simplifies a lot of code in QueryBuilderParser.php This also always loads the target table data now (which we want) * Make bill_id the PRIMARY index for the bills table * Load macros from a json file in misc instead of the database. * Fix whitespace and wrong key for collection. * Handle IN properly when generating SQL * Fix glue (devices.device_id = ports.port_id) is incorrect :D Show ALL tables we can resolve relationships for in the query builder filter. * Remove all macros from the database Remove insert statements, leave updates to update user's existing rules.
2018-03-14 20:25:19 +00:00
$param = [];
2015-07-13 20:10:26 +02:00
if (isset($device['device_id']) && $device['device_id'] > 0) {
//device selected
$global_rules = "SELECT ar1.* FROM alert_rules AS ar1 WHERE ar1.id NOT IN (SELECT agm1.rule_id FROM alert_group_map AS agm1 UNION DISTINCT SELECT adm1.rule_id FROM alert_device_map AS adm1)";
$device_rules = "SELECT ar2.* FROM alert_rules AS ar2 WHERE ar2.id IN (SELECT adm2.rule_id FROM alert_device_map AS adm2 WHERE adm2.device_id=?)";
$param[] = $device['device_id'];
$device_group_rules = "SELECT ar3.* FROM alert_rules AS ar3 WHERE ar3.id IN (SELECT agm3.rule_id FROM alert_group_map AS agm3 LEFT JOIN device_group_device AS dgd3 ON agm3.group_id=dgd3.device_group_id WHERE dgd3.device_id=?)";
feature: Added new alert rule builder UI and rule mapping UI (#8293) * feature: Added new alert rule builder UI * Updated to export sql queries * More updates * more changes * removed debug * fix scrut * Updated to include import options + various other fixes * fix rule * Populate name from collection rules. * Fix default rule import Allow new and old style rules in the collection. Don't add new yet as I'm not sure GenSQL() is working. * Fix GenSQL call * Extract filter building to class so it is nicely contained in one place * moved schema * some fixes and tweaks * travis fixes * Some more features / updates * Fix up my mistakes when adding default rules * Use a modal for new alert (Incomplete) Larger dialog!! Remove page loading stuff. Working: Loading rules, resetting dialog, importing from collection. Not working yet: select width device limited rule access? don't know what this is... Lots of unused stuff to delete... * reload "table" after save * fixed editing rule * Auto select2 width * Reload window on save * Restore per-device alert. Remove debug. * Small cleanups. Rule Name first. * Restore button to button type. Rename schema. * Fixes: wrong command to reload window, remove extra attributes, rule is never passed * Fixed old rule editing * some small updates for old imports * travis update to use trusty * maybe travis fix * Ability to set alert rule mappings on the rule edit screen * pip installs one line, no quiet for deploy * update schema def * Fix style and some copyright headers * fix docs missing file * Allow new versions of snmpsim and libraries * Parser WIP * Fix default rules insert * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * small rule collection fix * Working on glues * Working on glues * Docs updates + small UI changes * Parser WIP * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * Working on glues * Working on glues * Add table mapping, should move to it's own class * WIP * Glue working!! * Extract Schema class * Some final touches. revert alerts_rules.json for now. * Finish up initial implementation Needs more tests * Fix a few places * small doc updates * Fix finding tables in grouped rules. * remove unused code * code format fixes * Some quick tests for Schema Simplified output for findRelationshipPath. Always includes start and target in the result. This simplifies a lot of code in QueryBuilderParser.php This also always loads the target table data now (which we want) * Make bill_id the PRIMARY index for the bills table * Load macros from a json file in misc instead of the database. * Fix whitespace and wrong key for collection. * Handle IN properly when generating SQL * Fix glue (devices.device_id = ports.port_id) is incorrect :D Show ALL tables we can resolve relationships for in the query builder filter. * Remove all macros from the database Remove insert statements, leave updates to update user's existing rules.
2018-03-14 20:25:19 +00:00
$param[] = $device['device_id'];
$device_location_rules = "SELECT ar4.* FROM alert_rules AS ar4 WHERE ar4.id IN (SELECT alm4.rule_id FROM alert_location_map AS alm4 LEFT JOIN devices AS d4 ON alm4.location_id=d4.location_id WHERE d4.device_id=?)";
$param[] = $device['device_id'];
$full_query = '('. $global_rules .') UNION DISTINCT ('. $device_rules .') UNION DISTINCT ('. $device_group_rules .') UNION DISTINCT ('. $device_location_rules .')';
} else {
// no device selected
$full_query = 'SELECT alert_rules.* FROM alert_rules';
2014-11-30 17:49:52 +00:00
}
2015-07-13 20:10:26 +02:00
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
$full_query .= ' ORDER BY name ASC';
$rule_list = dbFetchRows($full_query, $param);
$count = count($rule_list);
feature: Added new alert rule builder UI and rule mapping UI (#8293) * feature: Added new alert rule builder UI * Updated to export sql queries * More updates * more changes * removed debug * fix scrut * Updated to include import options + various other fixes * fix rule * Populate name from collection rules. * Fix default rule import Allow new and old style rules in the collection. Don't add new yet as I'm not sure GenSQL() is working. * Fix GenSQL call * Extract filter building to class so it is nicely contained in one place * moved schema * some fixes and tweaks * travis fixes * Some more features / updates * Fix up my mistakes when adding default rules * Use a modal for new alert (Incomplete) Larger dialog!! Remove page loading stuff. Working: Loading rules, resetting dialog, importing from collection. Not working yet: select width device limited rule access? don't know what this is... Lots of unused stuff to delete... * reload "table" after save * fixed editing rule * Auto select2 width * Reload window on save * Restore per-device alert. Remove debug. * Small cleanups. Rule Name first. * Restore button to button type. Rename schema. * Fixes: wrong command to reload window, remove extra attributes, rule is never passed * Fixed old rule editing * some small updates for old imports * travis update to use trusty * maybe travis fix * Ability to set alert rule mappings on the rule edit screen * pip installs one line, no quiet for deploy * update schema def * Fix style and some copyright headers * fix docs missing file * Allow new versions of snmpsim and libraries * Parser WIP * Fix default rules insert * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * small rule collection fix * Working on glues * Working on glues * Docs updates + small UI changes * Parser WIP * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * Working on glues * Working on glues * Add table mapping, should move to it's own class * WIP * Glue working!! * Extract Schema class * Some final touches. revert alerts_rules.json for now. * Finish up initial implementation Needs more tests * Fix a few places * small doc updates * Fix finding tables in grouped rules. * remove unused code * code format fixes * Some quick tests for Schema Simplified output for findRelationshipPath. Always includes start and target in the result. This simplifies a lot of code in QueryBuilderParser.php This also always loads the target table data now (which we want) * Make bill_id the PRIMARY index for the bills table * Load macros from a json file in misc instead of the database. * Fix whitespace and wrong key for collection. * Handle IN properly when generating SQL * Fix glue (devices.device_id = ports.port_id) is incorrect :D Show ALL tables we can resolve relationships for in the query builder filter. * Remove all macros from the database Remove insert statements, leave updates to update user's existing rules.
2018-03-14 20:25:19 +00:00
if (isset($_POST['page_number']) && $_POST['page_number'] > 0 && $_POST['page_number'] <= $count) {
2014-11-30 17:49:52 +00:00
$page_number = $_POST['page_number'];
feature: Added new alert rule builder UI and rule mapping UI (#8293) * feature: Added new alert rule builder UI * Updated to export sql queries * More updates * more changes * removed debug * fix scrut * Updated to include import options + various other fixes * fix rule * Populate name from collection rules. * Fix default rule import Allow new and old style rules in the collection. Don't add new yet as I'm not sure GenSQL() is working. * Fix GenSQL call * Extract filter building to class so it is nicely contained in one place * moved schema * some fixes and tweaks * travis fixes * Some more features / updates * Fix up my mistakes when adding default rules * Use a modal for new alert (Incomplete) Larger dialog!! Remove page loading stuff. Working: Loading rules, resetting dialog, importing from collection. Not working yet: select width device limited rule access? don't know what this is... Lots of unused stuff to delete... * reload "table" after save * fixed editing rule * Auto select2 width * Reload window on save * Restore per-device alert. Remove debug. * Small cleanups. Rule Name first. * Restore button to button type. Rename schema. * Fixes: wrong command to reload window, remove extra attributes, rule is never passed * Fixed old rule editing * some small updates for old imports * travis update to use trusty * maybe travis fix * Ability to set alert rule mappings on the rule edit screen * pip installs one line, no quiet for deploy * update schema def * Fix style and some copyright headers * fix docs missing file * Allow new versions of snmpsim and libraries * Parser WIP * Fix default rules insert * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * small rule collection fix * Working on glues * Working on glues * Docs updates + small UI changes * Parser WIP * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * Working on glues * Working on glues * Add table mapping, should move to it's own class * WIP * Glue working!! * Extract Schema class * Some final touches. revert alerts_rules.json for now. * Finish up initial implementation Needs more tests * Fix a few places * small doc updates * Fix finding tables in grouped rules. * remove unused code * code format fixes * Some quick tests for Schema Simplified output for findRelationshipPath. Always includes start and target in the result. This simplifies a lot of code in QueryBuilderParser.php This also always loads the target table data now (which we want) * Make bill_id the PRIMARY index for the bills table * Load macros from a json file in misc instead of the database. * Fix whitespace and wrong key for collection. * Handle IN properly when generating SQL * Fix glue (devices.device_id = ports.port_id) is incorrect :D Show ALL tables we can resolve relationships for in the query builder filter. * Remove all macros from the database Remove insert statements, leave updates to update user's existing rules.
2018-03-14 20:25:19 +00:00
} else {
$page_number = 1;
2014-11-30 17:49:52 +00:00
}
2015-07-13 20:10:26 +02:00
feature: Added new alert rule builder UI and rule mapping UI (#8293) * feature: Added new alert rule builder UI * Updated to export sql queries * More updates * more changes * removed debug * fix scrut * Updated to include import options + various other fixes * fix rule * Populate name from collection rules. * Fix default rule import Allow new and old style rules in the collection. Don't add new yet as I'm not sure GenSQL() is working. * Fix GenSQL call * Extract filter building to class so it is nicely contained in one place * moved schema * some fixes and tweaks * travis fixes * Some more features / updates * Fix up my mistakes when adding default rules * Use a modal for new alert (Incomplete) Larger dialog!! Remove page loading stuff. Working: Loading rules, resetting dialog, importing from collection. Not working yet: select width device limited rule access? don't know what this is... Lots of unused stuff to delete... * reload "table" after save * fixed editing rule * Auto select2 width * Reload window on save * Restore per-device alert. Remove debug. * Small cleanups. Rule Name first. * Restore button to button type. Rename schema. * Fixes: wrong command to reload window, remove extra attributes, rule is never passed * Fixed old rule editing * some small updates for old imports * travis update to use trusty * maybe travis fix * Ability to set alert rule mappings on the rule edit screen * pip installs one line, no quiet for deploy * update schema def * Fix style and some copyright headers * fix docs missing file * Allow new versions of snmpsim and libraries * Parser WIP * Fix default rules insert * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * small rule collection fix * Working on glues * Working on glues * Docs updates + small UI changes * Parser WIP * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * Working on glues * Working on glues * Add table mapping, should move to it's own class * WIP * Glue working!! * Extract Schema class * Some final touches. revert alerts_rules.json for now. * Finish up initial implementation Needs more tests * Fix a few places * small doc updates * Fix finding tables in grouped rules. * remove unused code * code format fixes * Some quick tests for Schema Simplified output for findRelationshipPath. Always includes start and target in the result. This simplifies a lot of code in QueryBuilderParser.php This also always loads the target table data now (which we want) * Make bill_id the PRIMARY index for the bills table * Load macros from a json file in misc instead of the database. * Fix whitespace and wrong key for collection. * Handle IN properly when generating SQL * Fix glue (devices.device_id = ports.port_id) is incorrect :D Show ALL tables we can resolve relationships for in the query builder filter. * Remove all macros from the database Remove insert statements, leave updates to update user's existing rules.
2018-03-14 20:25:19 +00:00
$start = (($page_number - 1) * $results);
2015-07-13 20:10:26 +02:00
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
?>
<div class="table-responsive">
<table id="alert-rules-table" class="table table-condensed table-hover table-striped">
<thead>
<tr>
<th data-column-id="Type">Type<th>
<th data-column-id="Name">Name</th>
<th data-column-id="Devices">Devices<th>
<th data-column-id="Transports">Transports<th>
<th data-column-id="Extra">Extra</th>
<th data-column-id="Rule">Rule</th>
<th data-column-id="Severity">Severity</th>
<th data-column-id="Status">Status</th>
<th data-column-id="Enabled">Enabled</th>
<th data-column-id="Action" style="width:86px;">Action</th>
</tr>
</thead>
<tbody>
<?php
$index = 0;
foreach ($rule_list as $rule) {
$index++;
if ($index < $start) {
continue;
}
if ($index > $start + $results) {
break;
}
$sub = dbFetchRows('SELECT * FROM alerts WHERE rule_id = ? ORDER BY `state` DESC, `id` DESC LIMIT 1', array($rule['id']));
$severity = dbFetchCell('SELECT severity FROM alert_rules where id = ?', array($rule['id']));
$ico = 'check';
2015-07-13 20:10:26 +02:00
$col = 'success';
$extra = '';
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
$status_msg = '';
2015-07-13 20:10:26 +02:00
if (sizeof($sub) == 1) {
$sub = $sub[0];
if ((int) $sub['state'] === 0) {
$ico = 'check';
2015-07-13 20:10:26 +02:00
$col = 'success';
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
$status_msg = "All devices matching " . $rule['name'] . " are OK";
}
if ((int) $sub['state'] === 1 || (int) $sub['state'] === 2) {
$alert_style = alert_layout($severity);
$ico = $alert_style['icon'];
$col = $alert_style['icon_color'];
$extra = $alert_style['background_color'];
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
$status_msg = "Some devices matching " . $rule['name'] . " are currently alerting";
2014-11-30 17:49:52 +00:00
}
2015-07-13 20:10:26 +02:00
}
$alert_checked = '';
$orig_ico = $ico;
$orig_col = $col;
$orig_class = $extra;
if ($rule['disabled']) {
$ico = 'pause';
$col = '';
$extra = 'active';
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
$status_msg = $rule['name'] . " is OFF";
} else {
2015-07-13 20:10:26 +02:00
$alert_checked = 'checked';
}
2015-07-13 20:10:26 +02:00
$rule_extra = json_decode($rule['extra'], true);
feature: Added new alert rule builder UI and rule mapping UI (#8293) * feature: Added new alert rule builder UI * Updated to export sql queries * More updates * more changes * removed debug * fix scrut * Updated to include import options + various other fixes * fix rule * Populate name from collection rules. * Fix default rule import Allow new and old style rules in the collection. Don't add new yet as I'm not sure GenSQL() is working. * Fix GenSQL call * Extract filter building to class so it is nicely contained in one place * moved schema * some fixes and tweaks * travis fixes * Some more features / updates * Fix up my mistakes when adding default rules * Use a modal for new alert (Incomplete) Larger dialog!! Remove page loading stuff. Working: Loading rules, resetting dialog, importing from collection. Not working yet: select width device limited rule access? don't know what this is... Lots of unused stuff to delete... * reload "table" after save * fixed editing rule * Auto select2 width * Reload window on save * Restore per-device alert. Remove debug. * Small cleanups. Rule Name first. * Restore button to button type. Rename schema. * Fixes: wrong command to reload window, remove extra attributes, rule is never passed * Fixed old rule editing * some small updates for old imports * travis update to use trusty * maybe travis fix * Ability to set alert rule mappings on the rule edit screen * pip installs one line, no quiet for deploy * update schema def * Fix style and some copyright headers * fix docs missing file * Allow new versions of snmpsim and libraries * Parser WIP * Fix default rules insert * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * small rule collection fix * Working on glues * Working on glues * Docs updates + small UI changes * Parser WIP * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * Working on glues * Working on glues * Add table mapping, should move to it's own class * WIP * Glue working!! * Extract Schema class * Some final touches. revert alerts_rules.json for now. * Finish up initial implementation Needs more tests * Fix a few places * small doc updates * Fix finding tables in grouped rules. * remove unused code * code format fixes * Some quick tests for Schema Simplified output for findRelationshipPath. Always includes start and target in the result. This simplifies a lot of code in QueryBuilderParser.php This also always loads the target table data now (which we want) * Make bill_id the PRIMARY index for the bills table * Load macros from a json file in misc instead of the database. * Fix whitespace and wrong key for collection. * Handle IN properly when generating SQL * Fix glue (devices.device_id = ports.port_id) is incorrect :D Show ALL tables we can resolve relationships for in the query builder filter. * Remove all macros from the database Remove insert statements, leave updates to update user's existing rules.
2018-03-14 20:25:19 +00:00
$device_count = dbFetchCell('SELECT COUNT(*) FROM alert_device_map WHERE rule_id=?', [$rule['id']]);
$group_count = dbFetchCell('SELECT COUNT(*) FROM alert_group_map WHERE rule_id=?', [$rule['id']]);
$location_count = dbFetchCell('SELECT COUNT(*) FROM alert_location_map WHERE rule_id=?', [$rule['id']]);
$popover_msg_parts = [];
$icon_indicator = 'fa fa-globe fa-fw text-success';
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
if ($device_count) {
$popover_msg_parts[] = 'Device';
feature: Added new alert rule builder UI and rule mapping UI (#8293) * feature: Added new alert rule builder UI * Updated to export sql queries * More updates * more changes * removed debug * fix scrut * Updated to include import options + various other fixes * fix rule * Populate name from collection rules. * Fix default rule import Allow new and old style rules in the collection. Don't add new yet as I'm not sure GenSQL() is working. * Fix GenSQL call * Extract filter building to class so it is nicely contained in one place * moved schema * some fixes and tweaks * travis fixes * Some more features / updates * Fix up my mistakes when adding default rules * Use a modal for new alert (Incomplete) Larger dialog!! Remove page loading stuff. Working: Loading rules, resetting dialog, importing from collection. Not working yet: select width device limited rule access? don't know what this is... Lots of unused stuff to delete... * reload "table" after save * fixed editing rule * Auto select2 width * Reload window on save * Restore per-device alert. Remove debug. * Small cleanups. Rule Name first. * Restore button to button type. Rename schema. * Fixes: wrong command to reload window, remove extra attributes, rule is never passed * Fixed old rule editing * some small updates for old imports * travis update to use trusty * maybe travis fix * Ability to set alert rule mappings on the rule edit screen * pip installs one line, no quiet for deploy * update schema def * Fix style and some copyright headers * fix docs missing file * Allow new versions of snmpsim and libraries * Parser WIP * Fix default rules insert * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * small rule collection fix * Working on glues * Working on glues * Docs updates + small UI changes * Parser WIP * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * Working on glues * Working on glues * Add table mapping, should move to it's own class * WIP * Glue working!! * Extract Schema class * Some final touches. revert alerts_rules.json for now. * Finish up initial implementation Needs more tests * Fix a few places * small doc updates * Fix finding tables in grouped rules. * remove unused code * code format fixes * Some quick tests for Schema Simplified output for findRelationshipPath. Always includes start and target in the result. This simplifies a lot of code in QueryBuilderParser.php This also always loads the target table data now (which we want) * Make bill_id the PRIMARY index for the bills table * Load macros from a json file in misc instead of the database. * Fix whitespace and wrong key for collection. * Handle IN properly when generating SQL * Fix glue (devices.device_id = ports.port_id) is incorrect :D Show ALL tables we can resolve relationships for in the query builder filter. * Remove all macros from the database Remove insert statements, leave updates to update user's existing rules.
2018-03-14 20:25:19 +00:00
$icon_indicator = 'fa fa-server fa-fw text-primary';
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
}
if ($group_count) {
$popover_msg_parts[] = 'Group';
feature: Added new alert rule builder UI and rule mapping UI (#8293) * feature: Added new alert rule builder UI * Updated to export sql queries * More updates * more changes * removed debug * fix scrut * Updated to include import options + various other fixes * fix rule * Populate name from collection rules. * Fix default rule import Allow new and old style rules in the collection. Don't add new yet as I'm not sure GenSQL() is working. * Fix GenSQL call * Extract filter building to class so it is nicely contained in one place * moved schema * some fixes and tweaks * travis fixes * Some more features / updates * Fix up my mistakes when adding default rules * Use a modal for new alert (Incomplete) Larger dialog!! Remove page loading stuff. Working: Loading rules, resetting dialog, importing from collection. Not working yet: select width device limited rule access? don't know what this is... Lots of unused stuff to delete... * reload "table" after save * fixed editing rule * Auto select2 width * Reload window on save * Restore per-device alert. Remove debug. * Small cleanups. Rule Name first. * Restore button to button type. Rename schema. * Fixes: wrong command to reload window, remove extra attributes, rule is never passed * Fixed old rule editing * some small updates for old imports * travis update to use trusty * maybe travis fix * Ability to set alert rule mappings on the rule edit screen * pip installs one line, no quiet for deploy * update schema def * Fix style and some copyright headers * fix docs missing file * Allow new versions of snmpsim and libraries * Parser WIP * Fix default rules insert * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * small rule collection fix * Working on glues * Working on glues * Docs updates + small UI changes * Parser WIP * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * Working on glues * Working on glues * Add table mapping, should move to it's own class * WIP * Glue working!! * Extract Schema class * Some final touches. revert alerts_rules.json for now. * Finish up initial implementation Needs more tests * Fix a few places * small doc updates * Fix finding tables in grouped rules. * remove unused code * code format fixes * Some quick tests for Schema Simplified output for findRelationshipPath. Always includes start and target in the result. This simplifies a lot of code in QueryBuilderParser.php This also always loads the target table data now (which we want) * Make bill_id the PRIMARY index for the bills table * Load macros from a json file in misc instead of the database. * Fix whitespace and wrong key for collection. * Handle IN properly when generating SQL * Fix glue (devices.device_id = ports.port_id) is incorrect :D Show ALL tables we can resolve relationships for in the query builder filter. * Remove all macros from the database Remove insert statements, leave updates to update user's existing rules.
2018-03-14 20:25:19 +00:00
$icon_indicator = 'fa fa-th fa-fw text-primary';
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
}
if ($location_count) {
$popover_msg_parts[] = 'Location';
$icon_indicator = 'fa fa-th fa-fw text-primary';
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
}
if (count($popover_msg_parts)) {
$popover_msg = implode(', ', $popover_msg_parts);
} else {
$popover_msg = 'Global';
2015-07-19 18:52:39 +01:00
}
$popover_msg .= ' alert Rule #' . $rule['id'];
feature: Added new alert rule builder UI and rule mapping UI (#8293) * feature: Added new alert rule builder UI * Updated to export sql queries * More updates * more changes * removed debug * fix scrut * Updated to include import options + various other fixes * fix rule * Populate name from collection rules. * Fix default rule import Allow new and old style rules in the collection. Don't add new yet as I'm not sure GenSQL() is working. * Fix GenSQL call * Extract filter building to class so it is nicely contained in one place * moved schema * some fixes and tweaks * travis fixes * Some more features / updates * Fix up my mistakes when adding default rules * Use a modal for new alert (Incomplete) Larger dialog!! Remove page loading stuff. Working: Loading rules, resetting dialog, importing from collection. Not working yet: select width device limited rule access? don't know what this is... Lots of unused stuff to delete... * reload "table" after save * fixed editing rule * Auto select2 width * Reload window on save * Restore per-device alert. Remove debug. * Small cleanups. Rule Name first. * Restore button to button type. Rename schema. * Fixes: wrong command to reload window, remove extra attributes, rule is never passed * Fixed old rule editing * some small updates for old imports * travis update to use trusty * maybe travis fix * Ability to set alert rule mappings on the rule edit screen * pip installs one line, no quiet for deploy * update schema def * Fix style and some copyright headers * fix docs missing file * Allow new versions of snmpsim and libraries * Parser WIP * Fix default rules insert * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * small rule collection fix * Working on glues * Working on glues * Docs updates + small UI changes * Parser WIP * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * Working on glues * Working on glues * Add table mapping, should move to it's own class * WIP * Glue working!! * Extract Schema class * Some final touches. revert alerts_rules.json for now. * Finish up initial implementation Needs more tests * Fix a few places * small doc updates * Fix finding tables in grouped rules. * remove unused code * code format fixes * Some quick tests for Schema Simplified output for findRelationshipPath. Always includes start and target in the result. This simplifies a lot of code in QueryBuilderParser.php This also always loads the target table data now (which we want) * Make bill_id the PRIMARY index for the bills table * Load macros from a json file in misc instead of the database. * Fix whitespace and wrong key for collection. * Handle IN properly when generating SQL * Fix glue (devices.device_id = ports.port_id) is incorrect :D Show ALL tables we can resolve relationships for in the query builder filter. * Remove all macros from the database Remove insert statements, leave updates to update user's existing rules.
2018-03-14 20:25:19 +00:00
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
echo "<tr class='".$extra."' id='rule_id_".$rule['id']."'>";
// Type
echo "<td colspan=\"2\"><div data-toggle='popover' data-placement='top' data-content=\"$popover_msg\" class=\"$icon_indicator\"></div></td>";
// Name
2015-07-13 20:10:26 +02:00
echo '<td>'.$rule['name'].'</td>';
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
// Devices (and Groups)
if ($rule['invert_map'] == 0) {
$groups_msg = 'Only devices in this group.';
$devices_msg = 'Only this device.';
$except_device_or_group = null;
}
if ($rule['invert_map'] == 1) {
$devices_msg = 'All devices EXCEPT this device. ';
$groups_msg = 'All devices EXCEPT this group.';
$except_device_or_group = '<strong><em>EXCEPT</em></strong> ';
}
$popover_position = 'right';
$locations = null;
if ($location_count) {
$location_query = 'SELECT locations.location, locations.id FROM alert_location_map, locations WHERE alert_location_map.rule_id=? and alert_location_map.location_id = locations.id ORDER BY location';
$location_maps = dbFetchRows($location_query, [$rule['id']]);
foreach ($location_maps as $location_map) {
$locations .= "$except_device_or_group<a href=\"/devices\/location=".$location_map['id']."\" data-container='body' data-toggle='popover' data-placement='$popover_position' data-content='View Devices for Location' target=\"_blank\">".$location_map['location']."</a><br>";
}
}
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
$groups = null;
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
if ($group_count) {
$group_query = 'SELECT device_groups.name, device_groups.id FROM alert_group_map, device_groups WHERE alert_group_map.rule_id=? and alert_group_map.group_id = device_groups.id ORDER BY name';
$group_maps = dbFetchRows($group_query, [$rule['id']]);
foreach ($group_maps as $group_map) {
$groups .= "$except_device_or_group<a href=\"/device-groups/" . $group_map['id'] . "/edit\" data-container='body' data-toggle='popover' data-placement='$popover_position' data-content='" . $group_map['name'] . "' title='$groups_msg' target=\"_blank\">" . $group_map['name'] . "</a><br>";
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
}
}
$devices = null;
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
if ($device_count) {
$device_query = 'SELECT devices.device_id,devices.hostname FROM alert_device_map, devices WHERE alert_device_map.rule_id=? and alert_device_map.device_id = devices.device_id ORDER BY hostname';
$device_maps = dbFetchRows($device_query, [$rule['id']]);
foreach ($device_maps as $device_map) {
$devices .= "$except_device_or_group<a href=\"/device/device=" . $device_map['device_id'] . "/tab=edit/\" data-container='body' data-toggle='popover' data-placement='$popover_position' data-content='" . $device_map['hostname'] . "' title='$devices_msg' target=\"_blank\">" . $device_map['hostname'] . "</a><br>";
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
}
}
echo "<td colspan='2'>";
if ($locations) {
echo $locations;
}
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
if ($groups) {
echo $groups;
}
if ($devices) {
echo $devices;
}
if (!$devices && !$groups && !$locations) {
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
// All Devices
echo "<a href=\"/devices\" data-container='body' data-toggle='popover' data-placement='$popover_position' data-content='View All Devices' target=\"_blank\">All Devices</a><br>";
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
}
echo "</td>";
// Transports
$transport_count=dbFetchCell('SELECT COUNT(*) FROM alert_transport_map WHERE rule_id=?', [$rule['id']]);
$transports_popover='right';
$transports=null;
if ($transport_count) {
$transport_maps = dbFetchRows('SELECT transport_or_group_id,target_type FROM alert_transport_map WHERE alert_transport_map.rule_id=? ORDER BY target_type', [$rule['id']]);
foreach ($transport_maps as $transport_map) {
$transport_name=null;
if ($transport_map['target_type'] == "group") {
$transport_name = dbFetchCell('SELECT transport_group_name FROM alert_transport_groups WHERE transport_group_id=?', [$transport_map['transport_or_group_id']]);
$transport_edit = "<a href='' data-toggle='modal' data-target='#edit-transport-group' data-group_id='" . $transport_map['transport_or_group_id'] . "' data-container='body' data-toggle='popover' data-placement='$transports_popover' data-content='Edit transport group $transport_name'>" . $transport_name . "</a>";
}
if ($transport_map['target_type'] == "single") {
$transport_name = dbFetchCell('SELECT transport_name FROM alert_transports WHERE transport_id=?', [$transport_map['transport_or_group_id']]);
$transport_edit = "<a href='' data-toggle='modal' data-target='#edit-alert-transport' data-transport_id='" . $transport_map['transport_or_group_id'] . "' data-container='body' data-toggle='popover' data-placement='$transports_popover' data-content='Edit transport $transport_name'>" . $transport_name . "</a>";
}
$transports .= $transport_edit . "<br>";
}
}
if (!$transport_count || !$transports) {
$default_transports = dbFetchRows('SELECT transport_id, transport_name FROM alert_transports WHERE is_default=1 ORDER BY transport_name', []);
foreach ($default_transports as $default_transport) {
$transport_edit = "<a href='' data-toggle='modal' data-target='#edit-alert-transport' data-transport_id='" . $default_transport['transport_id'] . "' data-container='body' data-toggle='popover' data-placement='$transports_popover' data-content='Edit default transport " . $default_transport['transport_name'] . "'>" . $default_transport['transport_name'] . "</a>";
$transports .= $transport_edit . "<br>";
}
}
if (!$transports) {
$transports = "none";
}
echo "<td colspan='2'>$transports</td>";
// Extra
echo '<td><small>Max: '.$rule_extra['count'].'<br />Delay: '.$rule_extra['delay'].'<br />Interval: '.$rule_extra['interval'].'</small></td>';
// Rule
2015-07-13 20:10:26 +02:00
echo "<td class='col-sm-4'>";
if ($rule_extra['invert'] === true) {
echo '<strong><em>Inverted</em></strong> ';
}
feature: Added new alert rule builder UI and rule mapping UI (#8293) * feature: Added new alert rule builder UI * Updated to export sql queries * More updates * more changes * removed debug * fix scrut * Updated to include import options + various other fixes * fix rule * Populate name from collection rules. * Fix default rule import Allow new and old style rules in the collection. Don't add new yet as I'm not sure GenSQL() is working. * Fix GenSQL call * Extract filter building to class so it is nicely contained in one place * moved schema * some fixes and tweaks * travis fixes * Some more features / updates * Fix up my mistakes when adding default rules * Use a modal for new alert (Incomplete) Larger dialog!! Remove page loading stuff. Working: Loading rules, resetting dialog, importing from collection. Not working yet: select width device limited rule access? don't know what this is... Lots of unused stuff to delete... * reload "table" after save * fixed editing rule * Auto select2 width * Reload window on save * Restore per-device alert. Remove debug. * Small cleanups. Rule Name first. * Restore button to button type. Rename schema. * Fixes: wrong command to reload window, remove extra attributes, rule is never passed * Fixed old rule editing * some small updates for old imports * travis update to use trusty * maybe travis fix * Ability to set alert rule mappings on the rule edit screen * pip installs one line, no quiet for deploy * update schema def * Fix style and some copyright headers * fix docs missing file * Allow new versions of snmpsim and libraries * Parser WIP * Fix default rules insert * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * small rule collection fix * Working on glues * Working on glues * Docs updates + small UI changes * Parser WIP * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * Working on glues * Working on glues * Add table mapping, should move to it's own class * WIP * Glue working!! * Extract Schema class * Some final touches. revert alerts_rules.json for now. * Finish up initial implementation Needs more tests * Fix a few places * small doc updates * Fix finding tables in grouped rules. * remove unused code * code format fixes * Some quick tests for Schema Simplified output for findRelationshipPath. Always includes start and target in the result. This simplifies a lot of code in QueryBuilderParser.php This also always loads the target table data now (which we want) * Make bill_id the PRIMARY index for the bills table * Load macros from a json file in misc instead of the database. * Fix whitespace and wrong key for collection. * Handle IN properly when generating SQL * Fix glue (devices.device_id = ports.port_id) is incorrect :D Show ALL tables we can resolve relationships for in the query builder filter. * Remove all macros from the database Remove insert statements, leave updates to update user's existing rules.
2018-03-14 20:25:19 +00:00
if (empty($rule['builder'])) {
$rule_display = $rule['rule'];
} elseif ($rule_extra['options']['override_query'] === 'on') {
$rule_display = 'Custom SQL Query';
feature: Added new alert rule builder UI and rule mapping UI (#8293) * feature: Added new alert rule builder UI * Updated to export sql queries * More updates * more changes * removed debug * fix scrut * Updated to include import options + various other fixes * fix rule * Populate name from collection rules. * Fix default rule import Allow new and old style rules in the collection. Don't add new yet as I'm not sure GenSQL() is working. * Fix GenSQL call * Extract filter building to class so it is nicely contained in one place * moved schema * some fixes and tweaks * travis fixes * Some more features / updates * Fix up my mistakes when adding default rules * Use a modal for new alert (Incomplete) Larger dialog!! Remove page loading stuff. Working: Loading rules, resetting dialog, importing from collection. Not working yet: select width device limited rule access? don't know what this is... Lots of unused stuff to delete... * reload "table" after save * fixed editing rule * Auto select2 width * Reload window on save * Restore per-device alert. Remove debug. * Small cleanups. Rule Name first. * Restore button to button type. Rename schema. * Fixes: wrong command to reload window, remove extra attributes, rule is never passed * Fixed old rule editing * some small updates for old imports * travis update to use trusty * maybe travis fix * Ability to set alert rule mappings on the rule edit screen * pip installs one line, no quiet for deploy * update schema def * Fix style and some copyright headers * fix docs missing file * Allow new versions of snmpsim and libraries * Parser WIP * Fix default rules insert * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * small rule collection fix * Working on glues * Working on glues * Docs updates + small UI changes * Parser WIP * reorganize * Legacy import first draft done * Implement saving Skip translation to sql for now * Working on glues * Working on glues * Working on glues * Add table mapping, should move to it's own class * WIP * Glue working!! * Extract Schema class * Some final touches. revert alerts_rules.json for now. * Finish up initial implementation Needs more tests * Fix a few places * small doc updates * Fix finding tables in grouped rules. * remove unused code * code format fixes * Some quick tests for Schema Simplified output for findRelationshipPath. Always includes start and target in the result. This simplifies a lot of code in QueryBuilderParser.php This also always loads the target table data now (which we want) * Make bill_id the PRIMARY index for the bills table * Load macros from a json file in misc instead of the database. * Fix whitespace and wrong key for collection. * Handle IN properly when generating SQL * Fix glue (devices.device_id = ports.port_id) is incorrect :D Show ALL tables we can resolve relationships for in the query builder filter. * Remove all macros from the database Remove insert statements, leave updates to update user's existing rules.
2018-03-14 20:25:19 +00:00
} else {
$rule_display = QueryBuilderParser::fromJson($rule['builder'])->toSql(false);
}
echo '<i>'.htmlentities($rule_display).'</i></td>';
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
// Severity
echo '<td>'.($rule['severity'] == "ok" ? strtoupper($rule['severity']) : ucwords($rule['severity'])).'</td>';
// Status
$status_popover='top';
echo "<td><span data-toggle='popover' data-placement='$status_popover' data-content='$status_msg' id='alert-rule-".$rule['id']."' class='fa fa-fw fa-2x fa-".$ico.' text-'.$col."'></span> ";
2015-07-13 20:10:26 +02:00
if ($rule_extra['mute'] === true) {
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
echo "<div data-toggle='popover' data-content='Alerts for " . $rule['name'] . " are muted' class='fa fa-fw fa-2x fa-volume-off text-primary' aria-hidden='true'></div></td>";
2015-07-13 20:10:26 +02:00
}
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
// Enabled
$enabled_popover='top';
2015-07-13 20:10:26 +02:00
echo '<td>';
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
if ($rule['disabled']) {
$enabled_msg = $rule['name'] . " is OFF";
}
if (!$rule['disabled']) {
$enabled_msg = $rule['name'] . " is ON";
2015-07-13 20:10:26 +02:00
}
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
echo "<div id='on-off-checkbox-" .$rule['id']. "' data-toggle='popover' data-placement='$enabled_popover' data-content='" . $enabled_msg . "' class='btn-group btn-group-sm' role='group'>";
echo "<input id='".$rule['id']."' type='checkbox' name='alert-rule' data-orig_class='".$orig_class."' data-orig_colour='".$orig_col."' data-orig_state='".$orig_ico."' data-alert_id='".$rule['id']."' data-alert_name='".$rule['name']."' data-alert_status='". $status_msg. "' ".$alert_checked." data-size='small' data-toggle='modal'>";
echo "</div>";
2015-07-13 20:10:26 +02:00
echo '</td>';
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
// Action
$action_popover='left';
echo '<td>';
echo "<div class='btn-group btn-group-sm' role='group'>";
echo "<button type='button' class='btn btn-primary' data-toggle='modal' data-placement='$action_popover' data-target='#create-alert' data-rule_id='".$rule['id']."' name='edit-alert-rule' data-content='Edit alert rule " . $rule['name'] . "' data-container='body'><i class='fa fa-lg fa-pencil' aria-hidden='true'></i></button> ";
echo "<button type='button' class='btn btn-danger' aria-label='Delete' data-placement='$action_popover' data-toggle='modal' data-target='#confirm-delete' data-alert_id='".$rule['id']."' data-alert_name='".$rule['name']."' name='delete-alert-rule' data-content='Delete alert rule " . $rule['name'] . "' data-container='body'><i class='fa fa-lg fa-trash' aria-hidden='true'></i></button>";
2015-07-13 20:10:26 +02:00
echo '</td>';
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
2015-07-13 20:10:26 +02:00
echo "</tr>\r\n";
}//end foreach
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
?>
</tbody>
</table>
</div>
<?php
// Pagination
2015-07-13 20:10:26 +02:00
if (($count % $results) > 0) {
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
echo '<div class="table-responsive">';
echo '<div class="col pull-left">';
echo generate_pagination($count, $results, $page_number);
echo '</div>';
echo '<div class="col pull-right">';
$showing_start = ($page_number*$results)-$results+1;
$showing_end = $page_number*$results;
if ($showing_end > $count) {
$showing_end = $count;
}
echo "<p class=\"pagination\">Showing $showing_start to $showing_end of $count alert rules</p>";
echo '</div>';
echo '</div>';
2014-11-30 17:49:52 +00:00
}
2015-07-13 20:10:26 +02:00
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
echo '<input type="hidden" name="page_number" id="page_number" value="'.$page_number.'">
2015-07-13 20:10:26 +02:00
<input type="hidden" name="results_amount" id="results_amount" value="'.$results.'">
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
</form>';
2015-07-13 20:10:26 +02:00
if ($count < 1) {
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
echo '<div class="row">
<div class="col-sm-12">
<form role="form" method="post">
' . csrf_field() . '
<p class="text-center">
<button type="submit" class="btn btn-success btn-lg" id="create-default" name="create-default"><i class="fa fa-plus"></i> Click here to create the default alert rules!</button>
</p>
</form>
</div>
</div>';
}
2014-11-30 17:49:52 +00:00
?>
<script>
2015-07-19 18:52:39 +01:00
$("[data-toggle='modal'], [data-toggle='popover']").popover({
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
trigger: 'hover'
2015-07-19 18:52:39 +01:00
});
2014-11-30 17:49:52 +00:00
$('#ack-alert').click('', function(e) {
event.preventDefault();
var alert_id = $(this).data("alert_id");
$.ajax({
type: "POST",
url: "ajax_form.php",
2015-07-13 20:10:26 +02:00
data: { type: "ack-alert", alert_id: alert_id },
success: function(msg){
$("#message").html('<div class="alert alert-info">'+msg+'</div>');
if(msg.indexOf("ERROR:") <= -1) {
setTimeout(function() {
location.reload(1);
}, 1000);
}
},
error: function(){
$("#message").html('<div class="alert alert-info">An error occurred acking this alert.</div>');
}
2014-11-30 17:49:52 +00:00
});
});
$("[name='alert-rule']").bootstrapSwitch('offColor','danger');
$('input[name="alert-rule"]').on('switchChange.bootstrapSwitch', function(event, state) {
event.preventDefault();
var $this = $(this);
var alert_id = $(this).data("alert_id");
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
var alert_name = $(this).data("alert_name");
var alert_status = $(this).data("alert_status");
2014-11-30 17:49:52 +00:00
var orig_state = $(this).data("orig_state");
var orig_colour = $(this).data("orig_colour");
var orig_class = $(this).data("orig_class");
$.ajax({
type: 'POST',
url: 'ajax_form.php',
2015-07-13 20:10:26 +02:00
data: { type: "update-alert-rule", alert_id: alert_id, state: state },
dataType: "html",
success: function(msg) {
if(msg.indexOf("ERROR:") <= -1) {
if(state) {
$('#alert-rule-'+alert_id).removeClass('fa-pause');
$('#alert-rule-'+alert_id).addClass('fa-'+orig_state);
2015-07-13 20:10:26 +02:00
$('#alert-rule-'+alert_id).removeClass('text-default');
$('#alert-rule-'+alert_id).addClass('text-'+orig_colour);
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
$('#alert-rule-'+alert_id).attr('data-content', alert_status);
$('#on-off-checkbox-'+alert_id).attr('data-content', alert_name+' is ON');
$('#rule_id_'+alert_id).removeClass('active');
$('#rule_id_'+alert_id).addClass(orig_class);
2015-07-13 20:10:26 +02:00
} else {
$('#alert-rule-'+alert_id).removeClass('fa-'+orig_state);
$('#alert-rule-'+alert_id).addClass('fa-pause');
2015-07-13 20:10:26 +02:00
$('#alert-rule-'+alert_id).removeClass('text-'+orig_colour);
$('#alert-rule-'+alert_id).addClass('text-default');
Renovated Alert Rules (#11115) * Change select order from id to name * added example icmp/snmp down rules given by @kkrumm1 * Renovated Alert Rules * Defaulted sort by name * Moved top buttons and results selector outside of table and aligned them with pull-left and pull-right * Collapsed '#' (ID) into 'Type' and added titles for the icons * Added Devices and Transports columns for each rule * Moved Extra column next to transports * Added icons for Enabled when a user does not have global admin * Changed row_# variable to rule_id_# * Some 'else' cleanup * Added various title tags for more information when hovering * Moved pagination outside of table and align it with pull-left and added a bootgrid style summary pulled-right * Added table & th tags for bootgrid (but didn't turn it on) * code climate, round 1 * code climate, round 2 * add hrefs for device & device group edit * added trailing slash for device-groups/../edit/ * prevent #name conflict with transport modal * add hrefs for transport & transport group edit * use popover consistently * code climate, round 3 * removed unused variables * code climate, round 4 * popover variables * reload after successful delete * more informative feedback * use toastr, not #message, & don't reload * added license header & fail faster if not admin * use (more informative) ajax error message * delete confirmation with alert name in the modal * print each device per line * add href for all devices * refresh status & enabled data-content when/if a rule is turned on/off * use DRY style per @SourceDoctor (& my) preference); codeclimate meh * point devices popover to the right
2020-02-09 20:06:12 -05:00
$('#alert-rule-'+alert_id).attr('data-content', alert_name+' is OFF');
$('#on-off-checkbox-'+alert_id).attr('data-content', alert_name+' is OFF');
$('#rule_id_'+alert_id).removeClass('warning');
$('#rule_id_'+alert_id).addClass('active');
2015-07-13 20:10:26 +02:00
}
2014-11-30 17:49:52 +00:00
} else {
2015-07-13 20:10:26 +02:00
$("#message").html('<div class="alert alert-info">'+msg+'</div>');
$('#'+alert_id).bootstrapSwitch('toggleState',true );
}
},
error: function() {
$("#message").html('<div class="alert alert-info">This alert could not be updated.</div>');
$('#'+alert_id).bootstrapSwitch('toggleState',true );
2014-11-30 17:49:52 +00:00
}
});
});
function updateResults(results) {
2015-07-13 20:10:26 +02:00
$('#results_amount').val(results.value);
$('#page_number').val(1);
$('#result_form').submit();
2014-11-30 17:49:52 +00:00
}
function changePage(page,e) {
e.preventDefault();
$('#page_number').val(page);
$('#result_form').submit();
}
</script>