Blog - Latest News

05 Oct 2012

Munin plugin to track available updates in yum

This Munin 2.x plugin tracks available updates on servers with yum. It displays information in a group named yum. I modified the original plugin :
- on line 34 to make it work with Munin 2.x
- on line 76 to display a graph and to view alerts like this :

Here is the script to link in your /etc/munin/plugins/ directory :

#!/usr/bin/perl -w
# -*- perl -*-
# vim: ft=perl : sw=4 : ts=4 : et

=head1 NAME

yum - Plugin for monitoring pending package upgrades with yum

=head1 USAGE

This plugin needs to be called with the 'update' argument
from cron to work as intended.

=head1 AUTHOR

Copyright 2006 Dagfinn Ilmari Mannsåker <>
Copyright 2011 Adds by potsky <>

=head1 LICENSE



 #%# family=auto
 #%# capabilities=autoconf


use strict;
use Munin::Common::Defaults;

my $statefile = "$Munin::Common::Defaults::MUNIN_PLUGSTATE/yum.state";

sub update {
    if (-l $statefile) {
    die "$statefile is a symlink, not touching.\n";

    open my $state, '>', $statefile
    or die "Can't open $statefile for writing: $!\n";

    open my $yum, '-|', 'yum list updates'
    or die "Can't run 'yum list updates': $!";

    # Skip header crap
    while (<$yum>) {
    last if /^Updated/;

    while (<$yum>) {
    next unless /^(\S+)\.\S+\s+\S+\s+\S+/;
    print $state "$1\n";

    close $yum or die "Error running 'yum list updates': $!\n";
    close $state or die "Error writing $statefile: $!\n";

sub autoconf {
    if (system('yum --version >/dev/null 2>/dev/null') != 0) {
        print "no (Could not run yum)\n";
    elsif (! -r $statefile) {
        print "no (Could not find statefile.  Please read 'munindoc yum')\n";
    else {
        print "yes\n";
    exit 0;

sub config {
    print "graph_title Pending packages\n";
    print "graph_category yum\n";
    print "graph yes\n";
    print "pending.label pending\n";
    print "pending.warning 0:0\n";

sub report {
    my @packages;

    open my $state, '<', $statefile
    or die "Can't open $statefile for reading: $!
Please read 'munindoc yum' to understand why if the file does not exist.\n";

    chomp(@packages = <$state>);
    close $state;

    print 'pending.value ', scalar(@packages), "\n";
    print 'pending.extinfo ', join(' ', @packages), "\n"
    if @packages;

if ($ARGV[0]) {
    my $arg = $ARGV[0];
    my %funcs = (
        update   => \&update,
        config   => \&config,
        autoconf => \&autoconf,

    if (exists $funcs{$arg}) {
    } else {
    die "Unknown argument '$arg'\n";
} else {

Do not forget to add this line in the munin crontab to check updates :

$ sudo -u munin crontab -l
*/5 * * * * /usr/share/munin/plugins/yum update

Add this in /etc/munin/munin.conf to avoid email notification of yum updates for server :

$ tail /etc/munin/munin.conf
        yum.contacts no
        php_apc_fragmentation.contacts no
        php_apc_hit_miss.contacts no
        munin_stats.update.warning 100
        munin_stats.update.critical 120
Tags: , , , ,
1 reply
  1. MMin says:

    Thanks for sharing and publishing the script !!

    I made a small modification to it to list the security packages:


Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *