-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_dir_empty
executable file
·61 lines (52 loc) · 1.47 KB
/
check_dir_empty
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
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/python3
# Copyright (c) 2017 SUSE LLC All rights reserved.
#
# check_dir_empty 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, version 2 of
# the License.
#
# check_dir_empty 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 susePublicCloudInfoClient. If not, see
# <http://www.gnu.org/licenses/>.
#
"""
usage: check_dir_empty -h | --help
check_dir_empty -d DIRECTORY_PATH
options:
-h --help
Show help
-d
The path to the directory to be monitored to be empty or non existent
"""
import glob
import os
import sys
from docopt import docopt
# Command line processing
command_args = docopt(__doc__)
# Nagios states
OK = 0
WARNING = 1
CRITICAL = 2
UNKNOWN = 3
dir_to_monitor = command_args.get('DIRECTORY_PATH')
if not dir_to_monitor:
print(__doc__)
sys.exit(WARNING)
if not os.path.exists(dir_to_monitor):
sys.exit(OK)
else:
content = glob.glob('%s/*' % dir_to_monitor)
if content:
print(
'The directory "%s" does exist and is not empty' % dir_to_monitor
)
sys.exit(CRITICAL)
# Directory is empty, all is well
sys.exit(OK)