Fix alert and template test scripts (#10464)

This commit is contained in:
Tony Murray
2019-07-26 20:31:47 -05:00
committed by GitHub
parent 6394c35ce6
commit 9c8782a7da
2 changed files with 9 additions and 4 deletions

View File

@@ -1,6 +1,8 @@
#!/usr/bin/env php #!/usr/bin/env php
<?php <?php
use LibreNMS\Alert\RunAlerts;
$init_modules = ['alerts', 'laravel']; $init_modules = ['alerts', 'laravel'];
require __DIR__ . '/../includes/init.php'; require __DIR__ . '/../includes/init.php';
@@ -8,11 +10,12 @@ $options = getopt('t:h:r:p:s:d::');
if (isset($options['r']) && isset($options['h'])) { if (isset($options['r']) && isset($options['h'])) {
set_debug(isset($options['d'])); set_debug(isset($options['d']));
$runAlerts = new RunAlerts();
$rule_id = (int)$options['r']; $rule_id = (int)$options['r'];
$device_id = ctype_digit($options['h']) ? $options['h'] : getidbyname($options['h']); $device_id = ctype_digit($options['h']) ? $options['h'] : getidbyname($options['h']);
$where = "alerts.device_id = $device_id && alerts.rule_id = $rule_id"; $where = "alerts.device_id = $device_id && alerts.rule_id = $rule_id";
$alerts = loadAlerts($where); $alerts = $runAlerts->loadAlerts($where);
if (empty($alerts)) { if (empty($alerts)) {
echo "No active alert found, please check that you have the correct ids"; echo "No active alert found, please check that you have the correct ids";
exit(2); exit(2);
@@ -21,7 +24,7 @@ if (isset($options['r']) && isset($options['h'])) {
$alert['details']['delay'] = 0; $alert['details']['delay'] = 0;
$alert['note'] = 'Testing'; $alert['note'] = 'Testing';
IssueAlert($alert); $runAlerts->issueAlert($alert);
} else { } else {
c_echo(" c_echo("
Info: Info:

View File

@@ -4,6 +4,7 @@
$init_modules = ['alerts', 'laravel']; $init_modules = ['alerts', 'laravel'];
require __DIR__ . '/../includes/init.php'; require __DIR__ . '/../includes/init.php';
use LibreNMS\Alert\RunAlerts;
use LibreNMS\Alert\Template; use LibreNMS\Alert\Template;
use LibreNMS\Alert\AlertData; 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'])) { if (isset($options['t']) && isset($options['h']) && isset($options['r'])) {
set_debug(isset($options['d'])); set_debug(isset($options['d']));
$runAlerts = new RunAlerts();
$template_id = $options['t']; $template_id = $options['t'];
$device_id = ctype_digit($options['h']) ? $options['h'] : getidbyname($options['h']); $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']; $where .= ' alerts.state=' . (int)$options['s'];
} }
$alerts = loadAlerts($where); $alerts = $runAlerts->loadAlerts($where);
if (empty($alerts)) { if (empty($alerts)) {
echo "No alert found, make sure to select an active alert.\n"; echo "No alert found, make sure to select an active alert.\n";
exit(2); exit(2);
} }
$obj = DescribeAlert($alerts[0]); $obj = $runAlerts->describeAlert($alerts[0]);
if (isset($options['p'])) { if (isset($options['p'])) {
$obj['transport'] = $options['p']; $obj['transport'] = $options['p'];
} }