. * * @package LibreNMS * @link http://librenms.org * @copyright 2016 Neil Lathwood * @author Neil Lathwood */ if (!is_admin()) { echo("Insufficient Privileges"); exit(); } $hostname = escapeshellcmd($_REQUEST['hostname']); $type = $_REQUEST['type']; switch ($type) { case 'alerts': $filename = "alerts-$hostname.txt"; $device_id = getidbyname($hostname); $device = device_by_id_cache($device_id); $rules = GetRules($device_id); $output = ''; foreach ($rules as $rule) { $sql = GenSQL($rule['rule']); $qry = dbFetchRow($sql, array($device_id)); if (is_array($qry)) { $response = 'matches'; } else { $response = 'no match'; } $output .= 'Rule name: ' . $rule['name'] . PHP_EOL; $output .= 'Alert rule: ' . $rule['rule'] . PHP_EOL; $output .= 'Rule match: ' . $response . PHP_EOL . PHP_EOL; } break; default: echo 'You must specify a valid type'; exit(); } // ---- Output ---- if ($_GET['format'] == 'text') { header("Content-type: text/plain"); header('X-Accel-Buffering: no'); echo $output; } elseif ($_GET['format'] == 'download') { file_download($filename, $output); }