#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-

# Author: Jens Giessmann jg@handcode.de
# Date: 2017-07-14
# Version: 0.1.2

# check running and (last) installed kernel versions
# if != return WARNING

# needs plugin installed on clients

# the inventory function (dummy)
def inventory_kernel_version_compare(info):
   k_info = info[0]
   k_name = k_info[0]
   yield k_name, None

def check_kernel_version_compare(item, params, info):

   # get kernel infos from 1. line of client data
   # example line for FreeBSD:
   # FreeBSD 10.3-RELEASE-p18 10.3-RELEASE-p19
   k_info = info[0]
   k_name = k_info[0]
   k_run  = k_info[1]
   k_inst = k_info[2]

   # info string displayed in icinga
   info_warn = "Kernel version running %s != installed version %s. System needs reboot!" % (k_run, k_inst)
   info_ok = "Kernel version running %s match installed version" % (k_run)

   # return status code
   if k_run != k_inst:
      return 1, info_warn
   else:
      return 0, info_ok


check_info["kernel_version_compare"] = {
   'check_function':            check_kernel_version_compare,
   'inventory_function':        inventory_kernel_version_compare,
   'service_description':       'Kernel-Version',
   'has_perfdata':              False,
}
