#!/usr/bin/env python # # Authors: # rafael@postgresql.org.es / http://www.postgresql.org.es/ # # Copyright (c) 2015 USIT-University of Oslo # # zabbix_filesystem_not_monitored.py: Used by zabbix_agent to find out if # a filesystem does not have to be monitored. # # zabbix_filesystem_not_monitored.py 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, either version # 3 of the License, or (at your option) any later version. # # zabbix_filesystem_not_monitored.py is distributed in the hope that it will # be useful, but WITHOUT ANY WARRANTY; without even the implied # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with sms_send. If not, see . # import os import sys import glob # ################################################################### # Method: get_filesystem_not_monitored_status() # Parameters: filesystem # # Used to read the file /etc/zabbix_filesystems_not_monitored.conf if it # exists. # # It will return 0 if filesystem is not defined in this file or if the # file does not exist, 1 otherwise. # # The format used to define a filesystem that will not be monitored is a # filesystem definition per line: # # # # Filesystems can match a specified pattern according to the rules # used by the Unix shell. No tilde expansion is done, but *, ?, and # character ranges expressed with [] will be correctly matched. For a # literal match, wrap the meta-characters in brackets. For example, # '[?]' matches the character '?'. # # Only mounted filesystem will be considered when reading filesystems # limits definitions in /etc/zabbix_filesystems_not_monitored.conf. # # ################################################################### def get_filesystem_not_monitored_status(filesystem): defined_filesystems = [] config_file = '/etc/zabbix_filesystems_not_monitored.conf' try: if os.path.isfile(config_file): fd = open(config_file, "r") for line in fd: line = line.replace('\n', '').strip() # # Lines starting with # or empty lines are ignored. # if line.find('#', 0) == -1 and line.strip() != '': defined_fs = line # Normalized absolutized version of the pathname # if filesystem does not include an absolute path if not os.path.isabs(defined_fs): defined_fs = os.path.abspath(defined_fs) # # Finds all the pathnames matching a specified # pattern according to the rules used by the Unix # shell. No tilde expansion is done, but *, ?, and # character ranges expressed with [] will be # correctly matched. For a literal match, wrap the # meta-characters in brackets. For example, '[?]' # matches the character '?'. # expanded_paths = glob.glob(defined_fs) # # Only mounted filesystem will be considered when # reading filesystems definitions in # /etc/zabbix_filesystems_not_monitored.conf. # for expanded_fs in expanded_paths: if os.path.ismount(expanded_fs): defined_filesystems.append(expanded_fs) # # Find out if the filesystem we are asking for exists in # /etc/zabbix_filesystems_not_monitored.conf. If it does # not exists, return 0 # if filesystem in defined_filesystems: print ("1") else: print ("0") else: # # Return 0 if the file /etc/filesystems_not_monitored.conf # does not exist. # print ("0") except Exception as exp: raise exp # ############################################ # Main # ############################################ if __name__ == '__main__': try: if len(sys.argv) == 2: fs = sys.argv[1] get_filesystem_not_monitored_status(fs) else: print ("Error: Wrong number of parameters") print ('Format: ' + sys.argv[0] + ' ') sys.exit(1) except Exception as e: print (e) sys.exit(1)