Monitor for available OS updates

Hi,

I would like to monitor for available OS updates. Especially on all my Raspberry Pis, but there are a few more machines that need that information. I just can’t figure out how to make telegraf gather that kind of information.
Icinga2 has a nice “apt” plugin for this, but I couldn’t find anything close for telegraf.

Could anybody point me in the right direction?

Thanks

/Ulrich

You could write a script that e.g. evaluates the output of apt list --upgradable and call this script once a day with the inputs.exec plugin.

Indeed, that is the solution I implemented yesterday.

I wrote a short perl script

#!/usr/bin/perl
use warnings;
use strict;

my $apt = `apt-get -s dist-upgrade -V`;

my $updates = 0;
my $security = 0;

foreach (split "\n", $apt) {
    next if !m/^Inst/;
    $updates++;
    $security++ if m/Security/;
}

print "linux_updates updates=$updates","i,security=$security","i,updatestatus=",$updates==0?"0i":$security==0?"1i":"2i","\n";

and configured telegraf

[[inputs.exec]]
  commands = ["/usr/local/bin/updates2telegraf"]
  timeout = "10s"
  data_format = "influx"
1 Like

Thanks for the perl code, great inspiration for getting this implemented in bash. However, what’s the ‘updatestatus’ output meant to show?

updatestatus is just a boolean value indicating if any updates are available. It is just a convinience function. Much easier to check for a boolean instead for two integer values.