#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# |          _           _           _       _   __   _______        |
# |       __| |_  ___ __| |__  _ __ | |__   / | /  \ |__ / _ \       |
# |      / _| ' \/ -_) _| / / | '  \| / /   | || () | |_ \_, /       |
# |      \__|_||_\___\__|_\_\_|_|_|_|_\_\   |_(_)__(_)___//_/        |
# |                                            check_mk 1.0.39       |
# |                                                                  |
# | Copyright Mathias Kettner 2009                mk@mathias-kettner |
# +------------------------------------------------------------------+
# 
# This file is part of check_mk 1.0.39.
# The official homepage is at http://mathias-kettner.de/check_mk.
# 
# check_mk is free software;  you can redistribute it and/or modify it
# under the  terms of the  GNU General Public License  as published by
# the Free Software Foundation in version 2.  check_mk is  distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
# ails.  You should have  received  a copy of the  GNU  General Public
# License along with GNU Make; see the file  COPYING.  If  not,  write
# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
# Boston, MA 02110-1301 USA.


def check_df_netapp(volume, params, info):
   # info columns: NAME SIZE USED
   infolines = [ l for l in info if l[0] == volume ]
   if len(infolines) == 0:
      return (2, "CRIT - volume %s is missing" % volume )
   elif len(infolines) > 1:
      return (3, "UNKNOWN - Volume listed more than once!")
   size_kb, used_kb = infolines[0][1:3]
   size_mb = float(size_kb) / 1024
   used_mb = float(used_kb) / 1024
   size_gb = float(size_mb) / 1024
   used_gb = float(used_mb) / 1024

   warn_mb, crit_mb, levelstext = get_filesystem_levels(g_hostname, volume, size_gb, params)
   warn, crit = params

   used_perc = int(round(float(used_kb) / float(size_kb) * 100))
   infotext = "%d%% used (%.1fG of %.1fG), %s" % (used_perc, used_gb, size_gb, levelstext)
   perfdata = [(volume, "%.2fMB" % used_mb, warn_mb, crit_mb, 0, size_mb)]
   if used_perc >= crit:
      return (2, "CRIT - " + infotext, perfdata)
   elif used_perc >= warn:
      return (1, "WARNING - " + infotext, perfdata)
   else:
      return (0, "OK - " + infotext, perfdata)

def inventory_df_netapp(checkname, info):
   return [ (volume, "%.1fG" % (float(size_kb)/1024/1024), inventory_df_check_params)
            for volume, size_kb, used_kb in info ]
      

check_info['df_netapp']        = (check_df_netapp, "fs_%s", 1, inventory_df_netapp)
snmp_info['df_netapp']         = ("enterprises.789.1.5.4.1", [ 2, 3, 4 ] )
precompile_params['df_netapp'] = precompile_filesystem_levels
