Monthly Archives: February 2015

OP5 Monitor notifications by RSS

If you are using OP5 Monitor free version for personal/non-production/lab use you will find that notifications by e-mail or SMS is a bit overkill and annoying.
So I created this simple RSS function that consists of a notification script that is called from a check commmand that writes the notification to a text file on the op5-monitor server, and a custom PHP-script that reads the same text file and presents it in RSS format.
This way I can add in a RSS browser and receive alerts that way instead.

NOTE: In OP5 Monitor 7+ it looks like you should use: /opt/monitor/op5/notify/custom instead of /opt/plugins/custom , I had trouble with this after upgrading.

# Comma is csv seperator so replace it with dot if found in output
OUTPUT=$(echo $5 | sed 's/,/./g')
UUID=$(cat /proc/sys/kernel/random/uuid)

Change the check command host-notify to the below (or create a new one)


Change the check command service-notify to the below (or create a new one)


Create the file /var/www/html/rss.php with the below content (note that “channel” is the same as contact)
Modify text, domain, etc as needed. Add your contacts/channels at the end.

$channel = $_GET['channel'];
if ($channel != "") {
          $monitoringfile = "/opt/monitor/var/notifications-$channel.csv";
          header("Content-Type: application/xml; charset=ISO-8859-1");
          $item = $_GET['item'];
          echo "
<rss version=\"2.0\">
    <title>OP5 Monitor - $channel alerts</title>
    <description>A list of monitoring alerts</description>
         $file = file($monitoringfile);
         $file = array_reverse($file);
         foreach($file as $line){
            $displayItem = false;
            if (strlen($line) > 5) {
              if (strlen($item) > 0) {
                if(strpos($line, $item) !== false) {
                  $displayItem = true;
              } else {
                $displayItem = true;
              if ($displayItem) {
                $datetime=date('D, d M Y H:i:s +0000', $columns[1]);
                if (strpos($columns[3], "|") > 0) {
                  $desc=split("\|", $columns[3]);
                } else {
                echo "
      <guid isPermaLink=\"false\">$columns[0]</guid>
      <author>OP5 Monitor</author>
           if ($counter > 100) break;
          echo "
} else {
       echo "
<h1>Choose channel</h1>
  <li><a href=\"rss.php?channel=monitor\">All alerts</a></li>
  <li><a href=\"rss.php?channel=lab\">Lab alerts</a></li>

And add this if you feel its needed.

echo >/opt/monitor/var/notifications-lab.csv
echo >/opt/monitor/var/notifications-monitor.csv

Automated rpm resigning using GPG key with passphrase

Sometimes you want to sign multiple RPMs with your custom GPG key using a script.
But what if your GPG key has a passphrase? (which it should)
You probably don´t want to sit by the keyboard and enter the passphrase for each RPM.

This is simpler approach than using gpg-agent, a bash function that uses expect to send the passphrase to the rpm command.

function resignrpm {
  expect << EOF
spawn rpm --resign $myrpm
match_max 100000
expect "Enter pass phrase:"
send -- "$PASSPHRASE\n"
expect "*#"

Note: The function doesn´t check the exit status from the rpm command, it will always return 0 …