mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Fix alert and template test scripts (#10464)
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
use LibreNMS\Alert\RunAlerts;
|
||||
|
||||
$init_modules = ['alerts', 'laravel'];
|
||||
require __DIR__ . '/../includes/init.php';
|
||||
|
||||
@@ -8,11 +10,12 @@ $options = getopt('t:h:r:p:s:d::');
|
||||
|
||||
if (isset($options['r']) && isset($options['h'])) {
|
||||
set_debug(isset($options['d']));
|
||||
$runAlerts = new RunAlerts();
|
||||
|
||||
$rule_id = (int)$options['r'];
|
||||
$device_id = ctype_digit($options['h']) ? $options['h'] : getidbyname($options['h']);
|
||||
$where = "alerts.device_id = $device_id && alerts.rule_id = $rule_id";
|
||||
$alerts = loadAlerts($where);
|
||||
$alerts = $runAlerts->loadAlerts($where);
|
||||
if (empty($alerts)) {
|
||||
echo "No active alert found, please check that you have the correct ids";
|
||||
exit(2);
|
||||
@@ -21,7 +24,7 @@ if (isset($options['r']) && isset($options['h'])) {
|
||||
|
||||
$alert['details']['delay'] = 0;
|
||||
$alert['note'] = 'Testing';
|
||||
IssueAlert($alert);
|
||||
$runAlerts->issueAlert($alert);
|
||||
} else {
|
||||
c_echo("
|
||||
Info:
|
||||
|
@@ -4,6 +4,7 @@
|
||||
$init_modules = ['alerts', 'laravel'];
|
||||
require __DIR__ . '/../includes/init.php';
|
||||
|
||||
use LibreNMS\Alert\RunAlerts;
|
||||
use LibreNMS\Alert\Template;
|
||||
use LibreNMS\Alert\AlertData;
|
||||
|
||||
@@ -11,6 +12,7 @@ $options = getopt('t:h:r:p:s:d::');
|
||||
|
||||
if (isset($options['t']) && isset($options['h']) && isset($options['r'])) {
|
||||
set_debug(isset($options['d']));
|
||||
$runAlerts = new RunAlerts();
|
||||
|
||||
$template_id = $options['t'];
|
||||
$device_id = ctype_digit($options['h']) ? $options['h'] : getidbyname($options['h']);
|
||||
@@ -21,13 +23,13 @@ if (isset($options['t']) && isset($options['h']) && isset($options['r'])) {
|
||||
$where .= ' alerts.state=' . (int)$options['s'];
|
||||
}
|
||||
|
||||
$alerts = loadAlerts($where);
|
||||
$alerts = $runAlerts->loadAlerts($where);
|
||||
if (empty($alerts)) {
|
||||
echo "No alert found, make sure to select an active alert.\n";
|
||||
exit(2);
|
||||
}
|
||||
|
||||
$obj = DescribeAlert($alerts[0]);
|
||||
$obj = $runAlerts->describeAlert($alerts[0]);
|
||||
if (isset($options['p'])) {
|
||||
$obj['transport'] = $options['p'];
|
||||
}
|
||||
|
Reference in New Issue
Block a user