4 # rafael@postgresql.org.es / http://www.postgresql.org.es/
6 # Copyright (c) 2015 USIT-University of Oslo
8 # zabbix_filesystem_not_monitored.py: Used by zabbix_agent to find out if
9 # a filesystem does not have to be monitored.
11 # zabbix_filesystem_not_monitored.py is free software: you can redistribute
12 # it and/or modify it under the terms of the GNU General Public
13 # License as published by the Free Software Foundation, either version
14 # 3 of the License, or (at your option) any later version.
16 # zabbix_filesystem_not_monitored.py is distributed in the hope that it will
17 # be useful, but WITHOUT ANY WARRANTY; without even the implied
18 # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 # See the GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with sms_send. If not, see <http://www.gnu.org/licenses/>.
29 # ###################################################################
30 # Method: get_filesystem_not_monitored_status()
31 # Parameters: filesystem
33 # Used to read the file /etc/zabbix_filesystems_not_monitored.conf if it
36 # It will return 0 if filesystem is not defined in this file or if the
37 # file does not exist, 1 otherwise.
39 # The format used to define a filesystem that will not be monitored is a
40 # filesystem definition per line:
44 # Filesystems can match a specified pattern according to the rules
45 # used by the Unix shell. No tilde expansion is done, but *, ?, and
46 # character ranges expressed with [] will be correctly matched. For a
47 # literal match, wrap the meta-characters in brackets. For example,
48 # '[?]' matches the character '?'.
50 # Only mounted filesystem will be considered when reading filesystems
51 # limits definitions in /etc/zabbix_filesystems_not_monitored.conf.
53 # ###################################################################
56 def get_filesystem_not_monitored_status(filesystem):
58 defined_filesystems = []
59 config_file = '/etc/zabbix_filesystems_not_monitored.conf'
63 if os.path.isfile(config_file):
64 fd = open(config_file, "r")
67 line = line.replace('\n', '').strip()
70 # Lines starting with # or empty lines are ignored.
73 if line.find('#', 0) == -1 and line.strip() != '':
77 # Normalized absolutized version of the pathname
78 # if filesystem does not include an absolute path
80 if not os.path.isabs(defined_fs):
81 defined_fs = os.path.abspath(defined_fs)
84 # Finds all the pathnames matching a specified
85 # pattern according to the rules used by the Unix
86 # shell. No tilde expansion is done, but *, ?, and
87 # character ranges expressed with [] will be
88 # correctly matched. For a literal match, wrap the
89 # meta-characters in brackets. For example, '[?]'
90 # matches the character '?'.
93 expanded_paths = glob.glob(defined_fs)
96 # Only mounted filesystem will be considered when
97 # reading filesystems definitions in
98 # /etc/zabbix_filesystems_not_monitored.conf.
101 for expanded_fs in expanded_paths:
102 if os.path.ismount(expanded_fs):
103 defined_filesystems.append(expanded_fs)
106 # Find out if the filesystem we are asking for exists in
107 # /etc/zabbix_filesystems_not_monitored.conf. If it does
108 # not exists, return 0
111 if filesystem in defined_filesystems:
118 # Return 0 if the file /etc/filesystems_not_monitored.conf
124 except Exception, exp:
128 # ############################################
130 # ############################################
132 if __name__ == '__main__':
136 if len(sys.argv) == 2:
139 get_filesystem_not_monitored_status(fs)
142 print "Error: Wrong number of parameters"
143 print 'Format: ' + sys.argv[0] + ' <filesystem>'