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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s