Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nagios-plugins
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
lcgdm
nagios-plugins
Commits
e7eb51d8
Commit
e7eb51d8
authored
13 years ago
by
abeche
Browse files
Options
Downloads
Patches
Plain Diff
Add check_filesystem_rw, probe from Nikhef (translate from perl to python)
parent
7da6d206
Branches
GeoXFPowUnitTest
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
plugins/check_filesystem_rw
+144
-0
144 additions, 0 deletions
plugins/check_filesystem_rw
with
144 additions
and
0 deletions
plugins/check_filesystem_rw
0 → 100755
+
144
−
0
View file @
e7eb51d8
#!/usr/bin/env python
##############################################################################
# Copyright (c) Members of the EGEE Collaboration. 2011.
# See http://www.eu-egee.org/partners/ for details on the copyright
# holders.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS
# OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##############################################################################
#
# NAME : check_filesystem_rw
#
# DESCRIPTION : Check if the filesystems are readable and writable
#
# AUTHORS : Alexandre.beche@cern.ch
#
##############################################################################
import
os
from
lcgdmcommon
import
*
class
check_filesystem_rw
:
"
Checks if the mounted filesystem are readable and writable
"
__version__
=
"
0.0.1
"
__nagios_id__
=
"
DM-FS-RW
"
DEFAULT_TYPES
=
"
ext2,ext3
"
# Specific parameters, where key = short, value = long (i.e. {"h":"help", "C:":"command="})
# getopt format. The long version will be the one passed even when the short is specified
__additional_opts__
=
{
"
t:
"
:
"
types=
"
}
# Specific usage information
__usage__
=
"""
\t
-t, --types
\t
Type of filesystem you want to check (default: %s)
For each mounted filesystem, the probe checks if it is readable and writable.
(Probe originally written in perl by Nikhef)
Description of work executed by the probe:
\t
1. Retrieve filesystem informations from /etc/mounts
"
.
\t
2. Check the mode (r, w, r/w) of each one.
\t
3. Trigger a Warning for each filesystem not writable.
"""
%
(
DEFAULT_TYPES
)
# Methods
def
__init__
(
self
,
opt
=
{},
args
=
[]):
"""
Constructor
@param opt Contains a dictionary with the long option name as the key, and the argument as value
@param args Contains the arguments not associated with any option
"""
opt_types
=
self
.
DEFAULT_TYPES
if
"
types
"
in
opt
:
opt_types
=
opt
[
"
types
"
]
self
.
types
=
opt_types
.
split
(
"
,
"
)
def
main
(
self
):
"""
Test code itself. May raise exceptions.
@return A tuple (exit code, message, performance)
"""
# check_filesystem_rw:
# Checks that all mounted ext2, ext3 and xfs filesystems are mounted 'rw'
fstab
=
{}
mounts
=
{}
try
:
for
line
in
os
.
popen
(
"
cat /etc/fstab
"
).
readlines
():
line
=
line
.
split
()
# Save interesting informations
mnt
,
fs
,
options
=
line
[
1
],
line
[
2
],
line
[
3
]
options
=
options
.
split
(
"
,
"
)
# Keep only interesting type of FS
if
fs
not
in
self
.
types
:
continue
for
opt
in
options
:
if
opt
in
[
'
defaults
'
,
'
rw
'
]:
fstab
[
mnt
]
=
"
rw
"
elif
opt
==
"
ro
"
:
fstab
[
mnt
]
=
"
ro
"
except
:
return
(
EX_UNKNOWN
,
"
Failed to open /etc/fstab
"
,
None
)
# read current local mounts
try
:
for
line
in
os
.
popen
(
"
cat /proc/mounts
"
).
readlines
():
line
=
line
.
split
()
# Save interesting informations
mnt
,
fs
,
options
=
line
[
1
],
line
[
2
],
line
[
3
]
options
=
options
.
split
(
"
,
"
)
# Keep only interesting type of FS
if
fs
not
in
self
.
types
:
continue
for
opt
in
options
:
if
opt
in
[
'
ro
'
,
'
rw
'
]:
mounts
[
mnt
]
=
opt
except
:
return
(
EX_UNKNOWN
,
"
Failed to open /proc/mounts
"
,
None
)
# Verify that every mountpoint in /etc/fstab is mounted with the correct options
exit
=
EX_OK
for
mnt
in
fstab
.
keys
():
if
mnt
not
in
mounts
.
keys
():
msg
+=
"
%s(not mounted)
"
%
(
mnt
)
exit
=
EX_CRITICAL
elif
fstab
[
mnt
]
!=
mounts
[
mnt
]:
msg
+=
"
%s(%s)
"
%
(
mnt
,
mounts
[
mnt
])
exit
=
EX_CRITICAL
;
if
exit
==
EX_OK
:
msg
=
"
All filesystem are R/W
"
return
(
exit
,
msg
,
None
)
# When called directly
if
__name__
==
"
__main__
"
:
run
(
check_filesystem_rw
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment