1 <?php
defined('SYSPATH') OR die('No direct access allowed.');
8 * Generate HTML-formatted representation of the on-disk nagios log
10 * @param $options A magical array of options to use - check source for more info
11 * @return HTML-representation of the log
13 public static function show_log_entries($options)
18 $etc_path = System_Model
::get_nagios_etc_path();
19 $cgi_cfg = $etc_path . '/cgi.cfg';
21 $showlog = self
::get_path();
22 $cmd = $showlog . " --cgi-cfg=" . $cgi_cfg;
24 foreach ($options as $k => $v) {
25 # support all the various 'hide' options
26 if (substr($k, 0, 4) === 'hide') {
27 $cmd .= ' --' . str_replace('_', '-', $k);
32 if (isset($v['hard']) && isset($v['soft'])) {
35 if (isset($v['hard'])) {
36 $cmd .= ' --state-type=hard';
37 } elseif (isset($v['soft'])) {
38 $cmd .= ' --state-type=soft';
41 case 'first': case 'last':
48 $cmd .= ' --' . str_replace('_', '-', $k) . '=' . $v;
51 $cmd .= " --host='" . join("' --host='", $v) . "'";
54 $cmd .= " --service='" . join("' --service='", $v) . "'";
60 if (!empty($options['host_state_options'])) {
61 $cmd .= ' --host-states=' . join(array_keys($options['host_state_options']));
63 if (!empty($options['service_state_options'])) {
64 $cmd .= ' --service-states=' . join(array_keys($options['service_state_options']));
67 if (empty($options['parse_forward'])) {
70 # invoke a hard limit in case the user didn't set any.
71 # This will prevent php from exiting with an out-of-memory
72 # error, and will also stop users' browsers from hanging
73 # when trying to load a gargantually large page
74 if (empty($options['limit']) && $limit !== false) {
75 $cmd .= ' --limit=' . $limit;
78 # Add the proper image url.
79 $cmd .= " --image-url=" . url
::base(false) .
80 'application/views/icons/16x16/';
82 if (!Auth
::instance()->authorized_for('system_information')) {
83 $cmd .= ' --hide-process --hide-commands ';
86 $send_objects = false;
87 if (!Auth
::instance()->authorized_for('hosts_view_all') ||
!Auth
::instance()->authorized_for('services_view_all')) {
89 $cmd .= ' --restrict-objects';
94 $descriptorspec = array(
95 0 => array('pipe', 'r'),
96 1 => array('pipe', 'w'), // really, php, no "I don't want to see it, just send it to the browser"?
97 2 => array('pipe', 'a'),
100 $process = proc_open($cmd, $descriptorspec, $pipes);
101 if (is_resource($process)) {
103 $pool = new HostPool_Model();
106 foreach ($set->it(array('name')) as $obj) {
107 $hosts[$obj->get_name()] = $obj->get_name();
109 fwrite($pipes[0], implode(';', $hosts));
110 fwrite($pipes[0], "\n");
111 $pool = new ServicePool_Model();
114 foreach ($set->it(array('host_name', 'description')) as $obj) {
115 $hname = $obj->get_host()->get_name();
116 if (!array_key_exists($hname, $hosts)) {
118 $svc[] = $obj->get_description();
121 fwrite($pipes[0], implode(';', $svc));
124 while (!feof($pipes[1])) {
125 echo fgets($pipes[1], 1024);
128 proc_close($process);
130 echo "Couldn't run showlog binary";
135 * Get path to showlog executable
137 public static function get_path()
139 $showlog = Kohana
::config('reports.showlog_path');
140 if (!file_exists($showlog) ||
!is_executable($showlog)) {
141 echo "Showlog program '$showlog' not installed or not executable.<br />\n";