Beta website

Monitor SolusVM Bandwith usage with Nagios

Overview

I run a mumble server with Exigent (now owned by Fluccs). Exigent use SolusVM for their VM Management interface which is a great easy to use product with a relatively nice interface.

It also has an API that clients can use to get information about their server, such as bandwidth, remote reboots and more. I wanted to make a script that monitors my VM’s bandwidth and alerts me when its nearing its max, so I did.

The Script

The script in question is below. Its just a quick PHP on I put together. I’ll hopefully port it over to bash one day, but today is not that day. Currently it takes very little configuration, you just need to set your key/hash and the URL of the SolusVM interface.

Check out the script, or download it below.

<?php
 
// Url to the client API
// Do NOT include the trailing slash
$url = "https://example.com:5353";
 
// Specify the key and hash to access the API
$postfields["key"] = "";
$postfields["hash"] = "";
$postfields["action"] = "status";

    // Send the query to the solusvm master
    // Note we have to use GET, POST seems to be broken.
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url . "/api/client/command.php?key=".$postfields['key']."&hash=".$postfields['hash']."&action=".$postfields['action']."&bw=true");
    curl_setopt($ch, CURLOPT_TIMEOUT, 20);
    curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
    // Uncomment the two lines below if your host is using a self-signed certificate
    // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    // curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $data = curl_exec($ch);
    curl_close($ch);

    // Parse the returned data and build an array
    preg_match_all('/<(.*?)>([^<]+)<\/\\1>/i', $data, $match);
    $result = array();
    foreach ($match[1] as $x => $y)
    {
      $result[$y] = $match[2][$x];
    }

    // Explode our bandwidth results so we can use them in a array
    $bandwidth_result = explode(',',$result['bw']);
    $bandwidth = $bandwidth_result['3'];

    // Do our checking to see if we've used to much bandwidth
    // At the moment we Warn if usage is above 80% and go Critical if it is above 90%
    // Change the values below if you want a warning earlier
    if ($bandwidth > 90) {
        echo "CRITICAL: ".$bandwidth."% used\n";
        exit(2);
    }
    elseif ($bandwidth > 80) {
        echo "WARNING: ".$bandwidth."% used\n";
        exit(1);
    }
    elseif ($bandwidth < 80) {
        echo "OK: ".$bandwidth."% used\n";
        exit(0);
    }

?>

View on View on GitHub/Download