{php}IPAM: Installation and Configuration on Ubuntu

I was recently evaluating IP address management systems to which I did seem to find a favourite in {php}IPAM which is an open source IP address management system, this is a PHP based application with MySQL database management using jQuery libraries, ajax and some HTML5/CSS3 features. The features list is quite rich and whilst not detailing them in full, satisfied my criteria of functional requirements of providing API and IP request modules in addition to the standard feature set we should look for in an IP address management system.

One of the goals of {php}IPAM is to provide a light IP address management system, and therefore in most use cases all components of the LAMP architecture can be deployed on a single host, in my case this would be Ubuntu 14.04 LTS.

Before installing and configuring {php}IPAM there is a requirement to install the the required packages for the LAMP architecture (Apache, MySQL, PHP) to run the {php]IPAM application. If your are installing a new instance of MySQL you will be prompted to set the password credential for the ‘root’ user during installation.

In my use case I will be leveraging the API module, which also requires the php extensions curl (php5-curl) and mycrypt (php-mcrypt).

sudo apt-get update 
sudo apt-get -y install apache2 mysql-server php5 php5-gmp php-pear php5-mysql php5-ldap wget php5-mcrypt php5-curl 

Now we will need to the download package from the repository, and extract this to the Apache Web Server root directory.

cd /tmp
wget http://hivelocity.dl.sourceforge.net/project/phpipam/phpipam-1.1.010.tar
sudo tar -xvf phpipam-1.1.0.10.tar -C /var/www

By default, during installation of Apache, this will create a default web site, we will remove the symbolic link from thefrom sites-available to the sites-enabled directory and then enable the rewrite module and restart the Apache Web Server (apache2) service to apply changes.

sudo a2dissite 000-default.conf
sudo a2enmod rewrite
service apache2 restart 

Now we will create the {php}IPAM virtual host file (/etc/apache2/sites-available/ipam.conf) using a text editor and configure as per the below example. In this example, I will be optionally enabling the SSL engine and specifying the paths to the SSL certificate file, private key and the certificate chain file.

<VirtualHost *:443>
    ServerName ipam.dean.local
     SSLEngine on
     SSLCertificateFile /etc/apache2/ssl/ipam.dean.local.crt
     SSLCertificateKeyFile /etc/apache2/ssl/ipam.dean.local.key
     SSLCertificateChainFile /etc/apache2/ssl/ipam.dean.local.chainfile.crt
     ServerAdmin serveradmin@dean.local
     DocumentRoot /var/www/phpipam
     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>​

Once the virtual host file has been created we will enable the site, enable the Apache SSL module and reload Apache to apply the configuration.

sudo a2enmod ssl 
sudo a2ensite ipam.conf
service apache2 restart 

Now we will configure the {php}IPAM database management system, which in this case is MySQL for the connection string, as all the components for the LAMP architecture are installed on a single host we can specify the hostname as ‘localhost’ and set a password for the user ‘phpipam’ to authenticate to the database ‘phpipam’.

$db['host'] = "localhost";
$db['user'] = "phpipam";
$db['pass'] = "enterasecurepassword";
$db['name'] = "phpipam";​

By browsing to the URL, in this example https://ipam.dean.local we may now initialise the {php}IPAM instance from the installation page select ‘Automatic Database Installation’ which will now create the phpipam MySQL database by supplying the MySQL root user credentials. The final step now is to set a site title and URL (you may choose to complete this at a later time), once these settings have been saved the installation is now complete and the {php}IPAM web application is available to accept connections and configure.

For those you still manage allocation of IP addresses by the use of spreadsheet, maybe it time to think about deploying an IP address management system (does not have to be {php}IPAM!), the above steps show {php}IPAM is simple to install and configure, if you have looked through the feature list provides a rich functionality and is an open-source project and through the extended API and IP request modules can integrate with your existing automation/continuous delivery implementations.

The headache of managing IP address allocation (or in fact most things!) in a spreadsheet reminds me of a comment made by Scott Bollinger ‘When the process is manually updating a spreadsheet you’ve already lost.’

Nagios XI: Host and Service details not being displayed

Recently, I was troubleshooting an issue with Nagios XI where host and service details where not being displayed from the web management console.

On investigating the log file at ‘/var/log/messages’ there was a number of errors identifying that a table in the MySQL database was crashed and was required to be repaired.

ndo2db: mysql_error: 'Table './nagios/nagios_timedeventqueue' is marked as crashed and should be repaired'

In order to repair the table marked as crashed, I ran the below on the Nagios XI monitoring server , reconnected to the web management console and both host and service details were displayed as expected.

myisamchk --safe-recover /var/lib/mysql/*/*.MYI

 

Report status of MOVEit Central tasks to Nagios XI

I recently had the requirements to enable the reporting of tasks runs for MOVEit Central to Nagios XI, with the following:

  • For each task report the status of the last task run.
  • Return a status of ‘OK’ where the task run status is reported as ‘Success’ or ‘No xfers’.
  • Return a status of ‘Critical’ where the task run status is reported as ‘Failure’.
  • Return a service status information message to contain the task run status and the timestamp.

By default, installations of MOVEit Central use MySQL for the database, therefore in order to create an external script using Powershell I was required to download and install MySQL Connector/NET  (http://dev.mysql.com/downloads/connector/net/) to provide a fully-managed ADO.NET driver for MySQL.

As I will be required to query multiple tasks within MOVEit Central, I will specify a command parameter for filtering the query to the MOVEit Central database:

Param ([string] $TaskName)

In order to establish  a connection to the MySQL database I will be required to load the MySQL.Data assembly into my powershell session. The assemblies can be found at ‘C:\Program Files (x86)\MySQL\MySQL Connector Net 6.7.4\Assemblies’, in my instance I will be using v2.0.

Add-Type -Path "C:\Program Files (x86)\MySQL\MySQL Connector Net 6.7.4\Assemblies\v2.0\MySql.Data.dll"

Now, we will create a connection string and establish the connection to the MySQL database, which is named ‘micstats’.

$Connection = New-Object "MySql.Data.MySqlClient.MySqlConnection"
$Connection.ConnectionString = "server=localhost;user=username;database=micstats;port=3306;password=password;"
$Connection.Open()

Once the connection the MySQL database has been established, the next step is to create and return a MySQL command object. For my requirements, I will be querying the micstats.taskruns table to return the most recent task filtered by the command parameter $TaskName.

$Command = $Connection.CreateCommand()
$Command.CommandText= ("SELECT * FROM micstats.taskruns WHERE TaskName = """ + $TaskName + """ ORDER  BY ID DESC LIMIT 1")

All that is left now is to send the command object to the connection and return the output in the form of a data reader.

$Reader=$Command.ExecuteReader()
$Reader.Read() | Out-Null

As per my requirements, all tasks runs that report the status of either ‘Success’ or ‘No xfers’ need will return the exit code of ‘0’ to set the service status to be ‘OK’. In order to return the status of the task, we will return the string of the ‘Success’ table from the query output. If the task status is returned as ‘Failure’ this will return the exit code of ‘2’ and set the service status to be ‘Critical’.

If ($Reader.GetString('Success') -eq "Success" -or $Reader.GetString('Success') -eq "No xfers")
{
$returncode = 0
}

If ($Reader.GetString('Success') -eq "Failure")
{ADO
$returncode = 2
}

Finally, we will generate the status information by returning the task status and return the timestamp of when the task completed, by returning the string of the ‘TimeEnded’ table and then close the connection to the MySQL database and exit the powershell session returning the exit code.

"Completed with " + $Reader.GetString('Success') + " at " + $Reader.GetString('TimeEnded') 
$Connection.Close()
exit $returncode

While the script was created to be executed as an external script within Nagios, this can be run standalone from Windows Powershell as below.

./Check-MOVEitCentralTask -TaskName <Task Name> 

If your are looking to add external scripts to Nagios such as this one see the below link for more information;

https://deangrant.wordpress.com/2013/09/12/creating-and-running-external-scripts-within-nagios-xi/

The full Windows Powershell script can be downloaded from the below link:

https://app.box.com/s/253p2q3xj94lhf4bfti1