From: <abe...@us...> - 2012-09-01 19:18:06
|
Revision: 5655 http://astlinux.svn.sourceforge.net/astlinux/?rev=5655&view=rev Author: abelbeck Date: 2012-09-01 19:17:59 +0000 (Sat, 01 Sep 2012) Log Message: ----------- web interface, add Zabbix Monitoring support Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/edit.php branches/1.0/package/webinterface/altweb/admin/network.php branches/1.0/package/webinterface/altweb/common/functions.php branches/1.0/package/webinterface/altweb/common/status.inc branches/1.0/package/webinterface/altweb/common/version.php Added Paths: ----------- branches/1.0/package/webinterface/altweb/admin/zabbix.php Modified: branches/1.0/package/webinterface/altweb/admin/edit.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/edit.php 2012-09-01 14:35:35 UTC (rev 5654) +++ branches/1.0/package/webinterface/altweb/admin/edit.php 2012-09-01 19:17:59 UTC (rev 5655) @@ -29,6 +29,7 @@ 'pptpd' => 'Restart PPTP VPN Server', 'miniupnpd' => 'Restart Univ. Plug\'n\'Play', 'apcupsd' => 'Restart UPS Daemon', + 'zabbix' => 'Restart Zabbix Monitor', 'asterisk' => 'Restart Asterisk', 'cron' => 'Reload Cron for root' ); @@ -203,6 +204,8 @@ $result = restartPROCESS($process, 34, $result, 'init'); } elseif ($process === 'apcupsd') { $result = restartPROCESS($process, 35, $result, 'init'); + } elseif ($process === 'zabbix') { + $result = restartPROCESS($process, 36, $result, 'init', 4); } elseif ($process === 'cron') { $result = updateCRON('root', 30, $result); } @@ -308,6 +311,8 @@ putHtml('<p style="color: green;">Universal Plug\'n\'Play has Restarted.</p>'); } elseif ($result == 35) { putHtml('<p style="color: green;">UPS Daemon has Restarted.</p>'); + } elseif ($result == 36) { + putHtml('<p style="color: green;">Zabbix Monitoring has Restarted.</p>'); } elseif ($result == 99) { putHtml('<p style="color: red;">Action Failed.</p>'); } elseif ($result == 999) { Modified: branches/1.0/package/webinterface/altweb/admin/network.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/network.php 2012-09-01 14:35:35 UTC (rev 5654) +++ branches/1.0/package/webinterface/altweb/admin/network.php 2012-09-01 19:17:59 UTC (rev 5655) @@ -775,6 +775,10 @@ $result = saveNETWORKsettings($NETCONFDIR, $NETCONFFILE); header('Location: /admin/dnshosts.php'); exit; + } elseif (isset($_POST['submit_zabbix'])) { + $result = saveNETWORKsettings($NETCONFDIR, $NETCONFFILE); + header('Location: /admin/zabbix.php'); + exit; } elseif (isset($_POST['submit_edit_dnsmasq_conf'])) { $result = saveNETWORKsettings($NETCONFDIR, $NETCONFFILE); if (is_writable($file = '/mnt/kd/dnsmasq.conf')) { @@ -870,6 +874,8 @@ $result = restartPROCESS($process, 34, $result, 'init'); } elseif ($process === 'apcupsd') { $result = restartPROCESS($process, 35, $result, 'init'); + } elseif ($process === 'zabbix') { + $result = restartPROCESS($process, 36, $result, 'init', 4); } } else { $result = 2; @@ -938,6 +944,8 @@ putHtml('<p style="color: green;">Universal Plug\'n\'Play has Restarted.</p>'); } elseif ($result == 35) { putHtml('<p style="color: green;">UPS Daemon has Restarted.</p>'); + } elseif ($result == 36) { + putHtml('<p style="color: green;">Zabbix Monitoring has Restarted.</p>'); } elseif ($result == 99) { putHtml('<p style="color: red;">Action Failed.</p>'); } elseif ($result == 100) { @@ -1017,6 +1025,8 @@ putHtml('<option value="miniupnpd"'.$sel.'>Restart Univ. Plug\'n\'Play</option>'); $sel = ($reboot_restart === 'apcupsd') ? ' selected="selected"' : ''; putHtml('<option value="apcupsd"'.$sel.'>Restart UPS Daemon</option>'); + $sel = ($reboot_restart === 'zabbix') ? ' selected="selected"' : ''; + putHtml('<option value="zabbix"'.$sel.'>Restart Zabbix Monitor</option>'); $sel = ($reboot_restart === 'asterisk') ? ' selected="selected"' : ''; putHtml('<option value="asterisk"'.$sel.'>Restart Asterisk</option>'); putHtml('</select>'); @@ -1381,6 +1391,9 @@ putHtml('DNS Forwarder & DHCP Server:'); putHtml('<input type="submit" value="Configure DNS Hosts" name="submit_dns_hosts" class="button" /></td></tr>'); putHtml('<tr class="dtrow1"><td style="text-align: left;" colspan="6">'); + putHtml('Zabbix Monitoring:'); + putHtml('<input type="submit" value="Configure Zabbix" name="submit_zabbix" class="button" /></td></tr>'); + putHtml('<tr class="dtrow1"><td style="text-align: left;" colspan="6">'); putHtml('FTP Server:'); putHtml('<select name="ftp">'); putHtml('<option value="">disabled</option>'); Added: branches/1.0/package/webinterface/altweb/admin/zabbix.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/zabbix.php (rev 0) +++ branches/1.0/package/webinterface/altweb/admin/zabbix.php 2012-09-01 19:17:59 UTC (rev 5655) @@ -0,0 +1,328 @@ +<?php + +// Copyright (C) 2012 Lonnie Abelbeck +// This is free software, licensed under the GNU General Public License +// version 3 as published by the Free Software Foundation; you can +// redistribute it and/or modify it under the terms of the GNU +// General Public License; and comes with ABSOLUTELY NO WARRANTY. + +// zabbix.php for AstLinux +// 08-31-2012 +// +// System location of rc.conf file +$CONFFILE = '/etc/rc.conf'; +// System location of /mnt/kd/rc.conf.d directory +$ZABBIXCONFDIR = '/mnt/kd/rc.conf.d'; +// System location of gui.zabbix.conf file +$ZABBIXCONFFILE = '/mnt/kd/rc.conf.d/gui.zabbix.conf'; + +$myself = $_SERVER['PHP_SELF']; + +require_once '../common/functions.php'; + +$startagents_menu = array ( + '1' => '1', + '2' => '2', + '3' => '3', + '4' => '4', + '8' => '8', + '12' => '12', + '16' => '16' +); + +$debuglevel_menu = array ( + '0' => 'none', + '1' => 'critical', + '2' => 'error', + '3' => 'warning', + '4' => 'debug' +); + +$timeout_menu = array ( + '1' => '1', + '2' => '2', + '3' => '3', + '4' => '4', + '5' => '5', + '10' => '10', + '20' => '20', + '30' => '30' +); + +// Function: saveZABBIXsettings +// +function saveZABBIXsettings($conf_dir, $conf_file) { + global $openssl; + + $result = 11; + + if (! is_dir($conf_dir)) { + return(3); + } + if (($fp = @fopen($conf_file,"wb")) === FALSE) { + return(3); + } + fwrite($fp, "### gui.zabbix.conf - start ###\n###\n"); + + $value = 'GUI_ZABBIX_DATA="'.$_POST['zabbix_enabled'].'~'.trim($_POST['zabbix_server']).'"'; + fwrite($fp, "### GUI Data\n".$value."\n"); + + if ($_POST['zabbix_enabled'] == '1') { + $value = 'ZABBIX_SERVER="'.trim($_POST['zabbix_server']).'"'; + } else { + $value = 'ZABBIX_SERVER=""'; + } + fwrite($fp, "### Server\n".$value."\n"); + + $value = 'ZABBIX_HOSTNAME="'.trim($_POST['agent_hostname']).'"'; + fwrite($fp, "### Agent Hostname\n".$value."\n"); + + $value = 'ZABBIX_LISTENPORT="'.trim($_POST['agent_listenport']).'"'; + fwrite($fp, "### Agent Listen Port\n".$value."\n"); + + $value = 'ZABBIX_STARTAGENTS="'.$_POST['zabbix_startagents'].'"'; + fwrite($fp, "### StartAgents\n".$value."\n"); + + $value = 'ZABBIX_DEBUGLEVEL="'.$_POST['zabbix_debuglevel'].'"'; + fwrite($fp, "### DebugLevel\n".$value."\n"); + + $value = 'ZABBIX_TIMEOUT="'.$_POST['zabbix_timeout'].'"'; + fwrite($fp, "### Timeout\n".$value."\n"); + + $value = 'ZABBIX_PROXY="'.$_POST['zabbix_proxy'].'"'; + fwrite($fp, "### Proxy Enable\n".$value."\n"); + + $value = 'ZABBIX_PROXY_HOSTNAME="'.trim($_POST['zabbix_proxy_hostname']).'"'; + fwrite($fp, "### Proxy Hostname\n".$value."\n"); + + $value = 'ZABBIX_SERVER_PORT="'.trim($_POST['zabbix_server_port']).'"'; + fwrite($fp, "### Server Port\n".$value."\n"); + + $value = 'ZABBIX_PROXY_AGENT="'.$_POST['zabbix_proxy_agent'].'"'; + fwrite($fp, "### Route Agent via Proxy\n".$value."\n"); + + fwrite($fp, "### gui.zabbix.conf - end ###\n"); + fclose($fp); + + return($result); +} + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $result = 1; + if (! $global_admin) { + $result = 999; + } elseif (isset($_POST['submit_save'])) { + $result = saveZABBIXsettings($ZABBIXCONFDIR, $ZABBIXCONFFILE); + } elseif (isset($_POST['submit_restart'])) { + $result = 99; + if (isset($_POST['confirm_restart'])) { + $result = restartPROCESS('zabbix', 10, $result, 'init', 4); + } else { + $result = 2; + } + } + header('Location: '.$myself.'?result='.$result); + exit; +} else { // Start of HTTP GET +$ACCESS_RIGHTS = 'admin'; +require_once '../common/header.php'; + + if (is_file($ZABBIXCONFFILE)) { + $db = parseRCconf($ZABBIXCONFFILE); + $cur_db = parseRCconf($CONFFILE); + } else { + $db = parseRCconf($CONFFILE); + $cur_db = NULL; + } + + putHtml("<center>"); + if (isset($_GET['result'])) { + $result = $_GET['result']; + if ($result == 2) { + putHtml('<p style="color: red;">No Action, check "Confirm" for this action.</p>'); + } elseif ($result == 3) { + putHtml('<p style="color: red;">Error creating file.</p>'); + } elseif ($result == 10) { + putHtml('<p style="color: green;">Zabbix Monitoring has Restarted.</p>'); + } elseif ($result == 11) { + putHtml('<p style="color: green;">Settings saved, click "Restart Client" to apply any changed settings.</p>'); + } elseif ($result == 99) { + putHtml('<p style="color: red;">Action Failed.</p>'); + } elseif ($result == 999) { + putHtml('<p style="color: red;">Permission denied for user "'.$global_user.'".</p>'); + } else { + putHtml('<p style="color: orange;">No Action.</p>'); + } + } else { + putHtml('<p> </p>'); + } + putHtml("</center>"); +?> + <center> + <table class="layout"><tr><td><center> + <form method="post" action="<?php echo $myself;?>"> + <table width="100%" class="stdtable"> + <tr><td style="text-align: center;" colspan="2"> + <h2>Zabbix Monitoring Configuration:</h2> + </td></tr><tr><td width="240" style="text-align: center;"> + <input type="submit" class="formbtn" value="Save Settings" name="submit_save" /> + </td><td class="dialogText" style="text-align: center;"> + <input type="submit" class="formbtn" value="Restart Zabbix" name="submit_restart" /> + – + <input type="checkbox" value="restart" name="confirm_restart" /> Confirm + </td></tr></table> + <table class="stdtable"> + <tr class="dtrow0"><td width="60"> </td><td width="100"> </td><td width="100"> </td><td> </td><td width="100"> </td><td width="80"> </td></tr> +<?php + putHtml('<tr class="dtrow0"><td class="dialogText" style="text-align: left;" colspan="6">'); + putHtml('<strong>Zabbix Server:</strong>'); + putHtml('</td></tr>'); + + if (($value = getVARdef($db, 'GUI_ZABBIX_DATA')) === '') { + if (($value = getVARdef($db, 'ZABBIX_SERVER', $cur_db)) !== '') { + $value = '1~'.$value; + } else { + $value = '0~'; + } + } + $datatokens = explode('~', $value, 2); + + putHtml('<tr class="dtrow1"><td style="text-align: right;" colspan="2">'); + putHtml('Monitoring:'); + putHtml('</td><td style="text-align: left;" colspan="4">'); + putHtml('<select name="zabbix_enabled">'); + $sel = ($datatokens[0] == '0') ? ' selected="selected"' : ''; + putHtml('<option value="0"'.$sel.'>disabled</option>'); + $sel = ($datatokens[0] == '1') ? ' selected="selected"' : ''; + putHtml('<option value="1"'.$sel.'>enabled</option>'); + putHtml('</select>'); + putHtml('</td></tr>'); + + putHtml('<tr class="dtrow1"><td style="text-align: right;" colspan="2">'); + putHtml('Server:'); + putHtml('</td><td style="text-align: left;" colspan="4">'); + $value = $datatokens[1]; + putHtml('<input type="text" size="56" maxlength="128" value="'.$value.'" name="zabbix_server" />'); + putHtml('</td></tr>'); + + putHtml('<tr class="dtrow1"><td style="text-align: right;" colspan="2">'); + putHtml('Server Port:'); + putHtml('</td><td style="text-align: left;" colspan="4">'); + if (($value = getVARdef($db, 'ZABBIX_SERVER_PORT', $cur_db)) === '') { + $value = '10051'; + } + putHtml('<input type="text" size="8" maxlength="12" value="'.$value.'" name="zabbix_server_port" />'); + putHtml('</td></tr>'); + + putHtml('<tr class="dtrow0"><td class="dialogText" style="text-align: left;" colspan="6">'); + putHtml('<strong>Zabbix Agent:</strong>'); + putHtml('</td></tr>'); + + putHtml('<tr class="dtrow1"><td style="text-align: right;" colspan="2">'); + putHtml('Agent Hostname:'); + putHtml('</td><td style="text-align: left;" colspan="4">'); + if (($value = getVARdef($db, 'ZABBIX_HOSTNAME', $cur_db)) === '') { + $value = getVARdef($db, 'HOSTNAME', $cur_db); + } + putHtml('<input type="text" size="32" maxlength="128" value="'.$value.'" name="agent_hostname" />'); + putHtml('</td></tr>'); + + putHtml('<tr class="dtrow1"><td style="text-align: right;" colspan="2">'); + putHtml('Agent ListenPort:'); + putHtml('</td><td style="text-align: left;" colspan="4">'); + if (($value = getVARdef($db, 'ZABBIX_LISTENPORT', $cur_db)) === '') { + $value = '10050'; + } + putHtml('<input type="text" size="8" maxlength="12" value="'.$value.'" name="agent_listenport" />'); + putHtml('</td></tr>'); + + putHtml('<tr class="dtrow1"><td style="text-align: right;" colspan="2">'); + putHtml('StartAgents:'); + putHtml('</td><td style="text-align: left;" colspan="4">'); + putHtml('<select name="zabbix_startagents">'); + if (($startagents = getVARdef($db, 'ZABBIX_STARTAGENTS', $cur_db)) === '') { + $startagents = '3'; + } + foreach ($startagents_menu as $key => $value) { + $sel = ($startagents === (string)$key) ? ' selected="selected"' : ''; + putHtml('<option value="'.$key.'"'.$sel.'>'.$value.'</option>'); + } + putHtml('</select>'); + putHtml('processes'); + putHtml('</td></tr>'); + + putHtml('<tr class="dtrow1"><td style="text-align: right;" colspan="2">'); + putHtml('DebugLevel:'); + putHtml('</td><td style="text-align: left;" colspan="4">'); + putHtml('<select name="zabbix_debuglevel">'); + if (($debuglevel = getVARdef($db, 'ZABBIX_DEBUGLEVEL', $cur_db)) === '') { + $debuglevel = '3'; + } + foreach ($debuglevel_menu as $key => $value) { + $sel = ($debuglevel === (string)$key) ? ' selected="selected"' : ''; + putHtml('<option value="'.$key.'"'.$sel.'>'.$value.'</option>'); + } + putHtml('</select>'); + putHtml('</td></tr>'); + + putHtml('<tr class="dtrow1"><td style="text-align: right;" colspan="2">'); + putHtml('Timeout:'); + putHtml('</td><td style="text-align: left;" colspan="4">'); + putHtml('<select name="zabbix_timeout">'); + if (($timeout = getVARdef($db, 'ZABBIX_TIMEOUT', $cur_db)) === '') { + $timeout = '3'; + } + foreach ($timeout_menu as $key => $value) { + $sel = ($timeout === (string)$key) ? ' selected="selected"' : ''; + putHtml('<option value="'.$key.'"'.$sel.'>'.$value.'</option>'); + } + putHtml('</select>'); + putHtml('secs'); + putHtml('</td></tr>'); + +if (is_file('/usr/bin/zabbix_proxy')) { + putHtml('<tr class="dtrow0"><td class="dialogText" style="text-align: left;" colspan="6">'); + putHtml('<strong>Zabbix Proxy:</strong>'); + putHtml('</td></tr>'); + + putHtml('<tr class="dtrow1"><td style="text-align: right;" colspan="2">'); + putHtml('Proxy:'); + putHtml('</td><td style="text-align: left;" colspan="4">'); + putHtml('<select name="zabbix_proxy">'); + $sel = (getVARdef($db, 'ZABBIX_PROXY', $cur_db) === 'no') ? ' selected="selected"' : ''; + putHtml('<option value="no"'.$sel.'>disabled</option>'); + $sel = (getVARdef($db, 'ZABBIX_PROXY', $cur_db) === 'yes') ? ' selected="selected"' : ''; + putHtml('<option value="yes"'.$sel.'>enabled</option>'); + putHtml('</select>'); + putHtml('</td></tr>'); + + putHtml('<tr class="dtrow1"><td style="text-align: right;" colspan="2">'); + putHtml('Proxy Hostname:'); + putHtml('</td><td style="text-align: left;" colspan="4">'); + if (($value = getVARdef($db, 'ZABBIX_PROXY_HOSTNAME', $cur_db)) === '') { + $value = 'proxy-'.getVARdef($db, 'HOSTNAME', $cur_db); + } + putHtml('<input type="text" size="32" maxlength="128" value="'.$value.'" name="zabbix_proxy_hostname" />'); + putHtml('</td></tr>'); + + putHtml('<tr class="dtrow1"><td style="text-align: right;" colspan="2">'); + putHtml('Route Agent via Proxy:'); + putHtml('</td><td style="text-align: left;" colspan="4">'); + putHtml('<select name="zabbix_proxy_agent">'); + $sel = (getVARdef($db, 'ZABBIX_PROXY_AGENT', $cur_db) === 'yes') ? ' selected="selected"' : ''; + putHtml('<option value="yes"'.$sel.'>enabled</option>'); + $sel = (getVARdef($db, 'ZABBIX_PROXY_AGENT', $cur_db) === 'no') ? ' selected="selected"' : ''; + putHtml('<option value="no"'.$sel.'>disabled</option>'); + putHtml('</select>'); + putHtml('</td></tr>'); +} + + putHtml('</table>'); + putHtml('</form>'); + + putHtml('</center></td></tr></table>'); + putHtml('</center>'); +} // End of HTTP GET +require_once '../common/footer.php'; + +?> Property changes on: branches/1.0/package/webinterface/altweb/admin/zabbix.php ___________________________________________________________________ Added: svn:executable + * Modified: branches/1.0/package/webinterface/altweb/common/functions.php =================================================================== --- branches/1.0/package/webinterface/altweb/common/functions.php 2012-09-01 14:35:35 UTC (rev 5654) +++ branches/1.0/package/webinterface/altweb/common/functions.php 2012-09-01 19:17:59 UTC (rev 5655) @@ -44,7 +44,7 @@ // Function: restartPROCESS // -function restartPROCESS($process, $ret_good, $ret_fail, $start = 'start') { +function restartPROCESS($process, $ret_good, $ret_fail, $start = 'start', $wait = '1') { $result = $ret_fail; $path = getenv('PATH'); $pathOK = ($path !== FALSE && $path !== ''); @@ -61,7 +61,7 @@ } } elseif ($start === 'start') { $cmd .= ';service '.$process.' stop >/dev/null 2>/dev/null'; - $cmd .= ';sleep 1'; + $cmd .= ';sleep '.$wait; $cmd .= ';/usr/sbin/gen-rc-conf'; $cmd .= ';service '.$process.' '.$start.' >/dev/null 2>/dev/null'; } elseif ($process === 'iptables') { @@ -69,7 +69,7 @@ $cmd .= ';service iptables restart >/dev/null 2>/dev/null'; } else { $cmd .= ';service '.$process.' stop >/dev/null 2>/dev/null'; - $cmd .= ';sleep 1'; + $cmd .= ';sleep '.$wait; $cmd .= ';/usr/sbin/gen-rc-conf'; if ($process === 'openvpn' || $process === 'openvpnclient' || $process === 'racoon' || $process === 'pptpd') { $cmd .= ';service iptables restart >/dev/null 2>/dev/null'; Modified: branches/1.0/package/webinterface/altweb/common/status.inc =================================================================== --- branches/1.0/package/webinterface/altweb/common/status.inc 2012-09-01 14:35:35 UTC (rev 5654) +++ branches/1.0/package/webinterface/altweb/common/status.inc 2012-09-01 19:17:59 UTC (rev 5655) @@ -70,6 +70,8 @@ $status['pptpd'] = 0; $status['apcupsd'] = 0; $status['syslogd'] = 0; + $status['zabbix_agentd'] = 0; + $status['zabbix_proxy'] = 0; $status['reboot'] = 0; $tmpfile = tempnam("/tmp", "PHP_"); @@ -95,6 +97,10 @@ $status['pptpd']++; } elseif (strpos($line, ' apcupsd') !== FALSE || strpos($line, '/apcupsd') !== FALSE) { $status['apcupsd']++; + } elseif (strpos($line, ' zabbix_agentd ') !== FALSE || strpos($line, '/zabbix_agentd ') !== FALSE) { + $status['zabbix_agentd']++; + } elseif (strpos($line, ' zabbix_proxy ') !== FALSE || strpos($line, '/zabbix_proxy ') !== FALSE) { + $status['zabbix_proxy']++; } elseif (strpos($line, 'reboot -d') !== FALSE) { $status['reboot']++; } @@ -618,6 +624,16 @@ } } +if (is_file('/etc/zabbix_agentd.conf')) { + putHtml("<h2>Zabbix Monitoring Status:</h2>"); + putHtml("<pre>"); + putText('Zabbix Agent: '.($daemon['zabbix_agentd'] == 0 ? 'ERROR - No' : $daemon['zabbix_agentd']).' active processes'); + if (is_file('/etc/zabbix_proxy.conf')) { + putText('Zabbix Proxy: '.($daemon['zabbix_proxy'] == 0 ? 'ERROR - No' : $daemon['zabbix_proxy']).' active processes'); + } + putHtml("</pre>"); +} + if (($cmd = getPREFdef($global_prefs, 'status_disk_usage')) !== 'no') { putHtml("<h2>Disk Usage:</h2>"); putHtml("<pre>"); Modified: branches/1.0/package/webinterface/altweb/common/version.php =================================================================== --- branches/1.0/package/webinterface/altweb/common/version.php 2012-09-01 14:35:35 UTC (rev 5654) +++ branches/1.0/package/webinterface/altweb/common/version.php 2012-09-01 19:17:59 UTC (rev 5655) @@ -1,6 +1,6 @@ <?php // version.php for AstLinux Alternate Web Interface -$GUI_VERSION = '1.8.14'; +$GUI_VERSION = '1.8.15'; ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |