As some people know, I previously “created” (mostly modified the check_swap plug-in to print RAM usage) check_ram in C. Now one of my problems for the past few months was putting the C plug-in as well as “supported” environment under the same hat. Today I had another look at the amount of available plug-ins in NagiosExchange. There are quite a few plug-ins available, but as I do have some experience with Python, I used the one written in Python.
It was rather easy hacking in support for performance data into it, as the below shows. Someone else already posted a non-unified diff for performance data support, but that ain’t quite right according to the Nagios plug-in development guidelines.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | --- check_ram.py.orig +++ check_ram.py @@ -1,6 +1,7 @@  #!/usr/bin/env python  #  #   Copyright Hari Sekhon 2007 +#   Copyright Christian Heim 2008  #  #   This program is free software; you can redistribute it and/or modify  #   it under the terms of the GNU General Public License as published by @@ -64,27 +65,30 @@      total_used_megs = float(memtotal-memfree) / 1024      total_free_megs = float(total_free) / 1024      memtotal_megs   = float(memtotal) / 1024 +     +    total_warning_threshold_megs = round(float(memtotal) * float(warning_threshold) / 100 / 1024) +    total_critical_threshold_megs = round(float(memtotal) * float(critical_threshold) / 100 / 1024)      if percent == True:          percentage_free = int( float(total_free) / float(memtotal) * 100 )          if percentage_free < critical_threshold: -            print "RAM CRITICAL: %d%% ram free (%d/%d MB used)" % (percentage_free,total_used_megs,memtotal_megs) +            print "RAM CRITICAL - %d%% free (%d MB out of %d MB) |ram=%dMB;%d;%d;0;%d" % (percentage_free,total_free_megs,memtotal_megs,total_free_megs,total_warning_threshold_megs,total_critical_threshold_megs,memtotal_megs)              return CRITICAL          elif percentage_free < warning_threshold: -            print "RAM WARNING: %d%% ram free (%d/%d MB used)" % (percentage_free,total_used_megs,memtotal_megs) +            print "RAM WARNING - %d%% free (%d MB out of %d MB) |ram=%dMB;%d;%d;0;%d" % (percentage_free,total_free_megs,memtotal_megs,total_free_megs,total_warning_threshold_megs,total_critical_threshold_megs,memtotal_megs)              return WARNING          else: -            print "RAM OK: %d%% ram free" % percentage_free +            print "RAM OK - %d%% free (%d MB out of %d MB) |ram=%dMB;%d;%d;0;%d" % (percentage_free,total_free_megs,memtotal_megs,total_free_megs,total_warning_threshold_megs,total_critical_threshold_megs,memtotal_megs)              return OK      else:          if total_free < critical_threshold: -            print "RAM CRITICAL: %dMB ram free (%d/%d MB used)" % (total_free_megs,total_used_megs,memtotal_megs) +            print "RAM CRITICAL - %d%% free (%d MB out of %d MB) |ram=%dMB;%d;%d;0;%d" % (percentage_free,total_free_megs,memtotal_megs,total_free_megs,total_warning_threshold_megs,total_critical_threshold_megs,memtotal_megs)              return CRITICAL          if total_free < warning_threshold: -            print "RAM WARNING: %dMB ram free (%d/%d MB used)" % (total_free_megs,total_used_megs,memtotal_megs) +            print "RAM WARNING - %d%% free (%d MB out of %d MB) |ram=%dMB;%d;%d;0;%d" % (percentage_free,total_free_megs,memtotal_megs,total_free_megs,total_warning_threshold_megs,total_critical_threshold_megs,memtotal_megs)              return WARNING          else: -            print "RAM OK: %dMB ram free" % (total_free_megs) +            print "RAM OK - %d%% free (%d MB out of %d MB) |ram=%dMB;%d;%d;0;%d" % (percentage_free,total_free_megs,memtotal_megs,total_free_megs,total_warning_threshold_megs,total_critical_threshold_megs,memtotal_megs)              return OK | 
Now, with that simple plug-in I can go ahead and package the thing separately, without the need to figure out a way to get them nagios-plugins to install some useful includes …