Nagios Menu Modifications
Server - Nagios

Nagios provides a menu that can be modified to fit individual needs. In order to facilitate changes in the menu, you will need to modify the code which is in the PHP pages. This means that the menu may reflect the style and changes you want but it also means that you will need to copy any changes to prepare for updates which may revert back to the standard installation.

 

Menu Modification: Connecting to Scripts

The menu can be manipulated to send input to scripts created or to activate scripts that have been designed to perform a function. Here is a simple example of two types of possibilities to create the necessary options; a text field and buttons which activate scripts to perform tasks. Before embarking on these changes, note that allowing the web interface to interact with scripts internally does create security issues. If PHP is running in safe mode the web interface cannot interact with scripts.

Nagios Menu Changes

 

The “Provisioning” section is created by modifying side.php found in /usr/local/nagios/share. It would be a good idea to save a copy of any files modified in this directory. Here is the code that was added.

 

<div class="navsection">

<div class="navsectiontitle">Provisioning</div>

<li><a href="/deploy.php" target="<?php echo $link_target;?>">Nagios Provisioning</a></li>

<li><a href="/os.php" target="<?php echo $link_target;?>">OS Provisioning</a></li>

 

In the example the two links “deploy.php” and “os.php” are PHP pages that have been created in order to provide an entry point for the text boxes and to then send the input to a script to apply the changes desired. Here is an example of what the PHP page will need to look like in order to make this work. Note that this script contains options to both use the input from users and also connect directly to scripts. There is not time and space to describe the aspects of PHP programming but from the example you should be able to create your own page.

 

 

<?php

 

$script1 = '/opt/deploy.sh';

$script2 = '/opt/backup.sh';

$script3 = '/opt/upgrade.sh';

 

$script = '';

 

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

 

if (isset($_POST['script1'])) {

$script = $script1;

} elseif (isset($_POST['script2'])) {

$script = $script2;

} else {

$script = $script3;

}

 

$old_path = getcwd();

 

chdir(dirname($script) . '/');

 

$output = shell_exec('./' . basename($script) . ' ' . $_POST['ip'] . ' ' . $_POST['mask']);

 

chdir($old_path);

 

echo '<pre>' . $output . '</pre>';

 

} else {

?>

<!DOCTYPE html>

<html>

<head>

<title>Provisiong Nagios</title>

</head>

<body>

<div class="navbarlogo">

<a href="http://www.nagios.org" target="_blank"><img src="/images/sblogo.png" height="39" width="140" border="0" alt="Nagios" /></a>

</div>

<br>

<br>

<H4> Nagios Provisioning</H4>

<form method="post">

<table style="border: 0">

<tr>

<td>IP Address</td>

<td><input type="text" name="ip"></td>

</tr>

<tr>

<td>Mask</td>

<td><input type="text" name="mask"></td>

</tr>

<tr>

<td>&nbsp;</td>

<td>

<input type="submit" style="display:block; width: 100%" name="script1" value="Verifiy Nagios">

<input type="submit" style="display:block; width: 100%" name="script2" value="Create Backup">

<input type="submit" style="display:block; width: 100%" name="script3" value="Upgrade Nagios">

</td>

</tr>

</table>

</form>

</body>

</html>

<?php

}

 

Save the PHP page in /usr/local/nagios/share. Once the PHP page has been created then you will need to create the script. Here is a simple bash shell script to verify the PHP page is talking to your script. Note that the “$1” is the first variable received and the “$2” is the second received.

 

#!/bin/bash

echo "IP Address Submitted $1"

echo "Netmask Submitted $2"

 

From that example you can see the basic structure and function that can be modified for various purposes. In the first example text fields are used to enter information sent to a backend script and then report the output to the screen.

Nagios Menu Modifications

Here you can see an example output of the text field entries from the script.

Nagios Menu Mods

Another way of interacting with script is to simply use a button to activate a script from the web interface. In the PHP code listed above there are three script examples listed. When the buttons are selected the user will also receive feedback in terms of what the script has done. Here is an example output from a backup.

 

 

Initiating Back Up for the Nagios Implementation

working ....

Verifying Backup

working ...

Removing Old Backup and Checking Disk Space

Backup Complete

Menu Modification for Reporting

The menu can also be modified to provide easier access to reporting on the specific reports that users require. The services which are modified by Nagios can be accessed from the menu as a group, example seen here. Note that many of the services have graphing options which are accessible by clicking on the graph.

Nagios Menu Modifications

However, the menu can be modified to provide access to specific graphing, for example, which the company would like to get access to quickly. In this example the CPU load is represented in a graph. Note the menu has been modified under Trends to allow access to specific information which may be required. Here is what the code looks like that needs to be entered into the side.php found in the /usr/local/nagios/share directory. Note the path that is used to pull up the graphs from Pnp4nagios.

 

 

<li><a href="/<?php echo $cfg["cgi_base_url"];?>/trends.cgi" target="<?php echo $link_target;?>">Trends</a></li>

<ul>

<li><a href="/pnp4nagios/index.php/graph?host=localhost&srv=Current%20Load" target="<?php echo $link_target;?>">Load History</a></li>

<li><a href="/pnp4nagios/index.php/graph?host=localhost&srv=Memory" target="<?php echo $link_target;?>">Memory</a></li>

<li><a href="/pnp4nagios/index.php/graph?host=localhost&srv=HTTP" target="<?php echo $link_target;?>">Web History</a></li>

<li><a href="/pnp4nagios/index.php/graph?host=localhost&srv=HTTP&view=0" target="<?php echo $link_target;?>">Web (4 hrs.)</a></li>

</ul>

The resulting menu change then provides quick access to often used material.

Nagios Menu Modification For Reporting

 

From these basic examples you would be able to build out any changes you would like to make.