Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
nagios-plugins
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Lysator
nagios-plugins
Commits
dd577a93
Commit
dd577a93
authored
18 years ago
by
Per Cederqvist
Browse files
Options
Downloads
Patches
Plain Diff
Added -n option, to specify the host name used for lookup in cfg file.
parent
d8f91b9e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
check_no_server
+25
-18
25 additions, 18 deletions
check_no_server
with
25 additions
and
18 deletions
check_no_server
+
25
−
18
View file @
dd577a93
...
@@ -20,30 +20,30 @@ def ok(hostname, msg):
...
@@ -20,30 +20,30 @@ def ok(hostname, msg):
print
"
OK - %s: %s
"
%
(
hostname
,
msg
)
print
"
OK - %s: %s
"
%
(
hostname
,
msg
)
sys
.
exit
(
0
)
sys
.
exit
(
0
)
def
check_no_server
(
host
name
,
port
,
cfg
):
def
check_no_server
(
host
addr
,
port
,
cfg
,
hostname
):
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
s
.
settimeout
(
7
)
s
.
settimeout
(
7
)
try
:
try
:
s
.
connect
((
host
name
,
port
))
s
.
connect
((
host
addr
,
port
))
except
socket
.
gaierror
,
err
:
except
socket
.
gaierror
,
err
:
warning
(
host
name
,
err
[
1
])
warning
(
host
addr
,
err
[
1
])
except
socket
.
timeout
:
except
socket
.
timeout
:
if
cfg
.
require
(
hostname
):
if
cfg
.
require
(
hostname
):
critical
(
host
name
,
"
timeout connecting to server
"
)
critical
(
host
addr
,
"
timeout connecting to server
"
)
else
:
else
:
ok
(
host
name
,
"
timeout connecting to server
"
)
ok
(
host
addr
,
"
timeout connecting to server
"
)
except
socket
.
error
,
e
:
except
socket
.
error
,
e
:
if
e
[
0
]
==
errno
.
ECONNREFUSED
:
if
e
[
0
]
==
errno
.
ECONNREFUSED
:
if
cfg
.
require
(
hostname
):
if
cfg
.
require
(
hostname
):
critical
(
host
name
,
e
[
1
])
critical
(
host
addr
,
e
[
1
])
else
:
else
:
ok
(
host
name
,
e
[
1
])
ok
(
host
addr
,
e
[
1
])
unknown
(
host
name
,
e
[
1
])
unknown
(
host
addr
,
e
[
1
])
if
cfg
.
allowed
(
hostname
):
if
cfg
.
allowed
(
hostname
):
ok
(
host
name
,
"
connection succeeded
"
)
ok
(
host
addr
,
"
connection succeeded
"
)
else
:
else
:
critical
(
host
name
,
"
connection succeeded
"
)
critical
(
host
addr
,
"
connection succeeded
"
)
class
CfgFile
(
object
):
class
CfgFile
(
object
):
def
__init__
(
self
,
fn
=
None
):
def
__init__
(
self
,
fn
=
None
):
...
@@ -69,33 +69,40 @@ def usage():
...
@@ -69,33 +69,40 @@ def usage():
def
main
():
def
main
():
import
getopt
import
getopt
host
=
None
host
addr
=
None
port
=
None
port
=
None
cfg
=
None
cfg
=
None
hostname
=
None
opts
,
args
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
"
H:p:c:
"
,
opts
,
args
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
"
H:p:c:n:
"
,
[
"
host=
"
,
"
port=
"
,
"
cfg=
"
])
[
"
host=
"
,
"
port=
"
,
"
cfg=
"
,
"
name=
"
])
for
opt
,
val
in
opts
:
for
opt
,
val
in
opts
:
if
opt
in
(
"
-H
"
,
"
--host
"
):
if
opt
in
(
"
-H
"
,
"
--host
"
):
host
=
val
host
addr
=
val
elif
opt
in
(
"
-p
"
,
"
--port
"
):
elif
opt
in
(
"
-p
"
,
"
--port
"
):
port
=
int
(
val
)
port
=
int
(
val
)
elif
opt
in
(
"
-c
"
,
"
--cfg
"
):
elif
opt
in
(
"
-c
"
,
"
--cfg
"
):
cfg
=
val
cfg
=
val
elif
opt
in
(
"
-n
"
,
"
--name
"
):
hostname
=
val
if
host
is
None
and
port
is
None
and
len
(
args
)
==
2
:
if
host
addr
is
None
and
port
is
None
and
len
(
args
)
==
2
:
host
=
args
[
0
]
host
addr
=
args
[
0
]
port
=
int
(
args
[
1
])
port
=
int
(
args
[
1
])
if
host
is
None
or
port
is
None
:
if
host
addr
is
None
or
port
is
None
:
usage
()
usage
()
if
cfg
is
not
None
:
if
cfg
is
not
None
:
cfg_data
=
CfgFile
(
cfg
)
cfg_data
=
CfgFile
(
cfg
)
else
:
else
:
cfg_data
=
CfgFile
()
cfg_data
=
CfgFile
()
if
hostname
is
None
:
hostname
=
hostaddr
check_no_server
(
host
,
port
,
cfg_data
)
check_no_server
(
host
addr
,
port
,
cfg_data
,
hostname
)
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
main
()
main
()
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