Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
icinga-checks
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
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
IML Open Source
icinga-checks
Commits
f3518944
Commit
f3518944
authored
3 years ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
add check_conn - check tcp and udp connections
parent
f93f964e
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
check_conn
+148
-0
148 additions, 0 deletions
check_conn
check_conn.cfg.dist
+19
-0
19 additions, 0 deletions
check_conn.cfg.dist
with
167 additions
and
0 deletions
check_conn
0 → 100755
+
148
−
0
View file @
f3518944
#!/usr/bin/env bash
# ======================================================================
#
# Check connection ... is a host available on a given port via tcp or udp
#
# requirements:
# - none
#
# ----------------------------------------------------------------------
# 2021-11-05 v0.0 <axel.hahn@iml.unibe.ch>
# ======================================================================
.
`
dirname
$0
`
/inc_pluginfunctions
cfgfile
=
$(
dirname
$0
)
/
$(
basename
$0
)
.cfg
out
=
""
# ----------------------------------------------------------------------
# functions
# ----------------------------------------------------------------------
function
getChecks
(){
while
[
$#
-gt
0
]
;
do
test
-r
"
$1
"
&&
grep
-E
"^(tcp|udp)/"
"
$1
"
2>&1
shift
1
done
}
function
showHelp
(){
cat
<<
EOF
______________________________________________________________________
CHECK_CONN check if is a host available on a given port via tcp or udp
from local machine
$(
hostname
-f
)
.
(c) Institute for Medical Education - Univerity of Bern
Licence: GNU GPL 3
______________________________________________________________________
SYNTAX:
`basename
$0
` OPTIONS
You can create a file named
$cfgfile
and add your connections there.
To start you can copy the file
$cfgfile
.dist
OPTIONS:
-h or --help show this help.
-t CONNECTION test given connection; This param ignores entries
in the config file. For multiple connection tests
quote the parameter value and set spaces between
the connections.
PARAMETERS:
CONNECTION Connection in the same syntax like in the config:
tcp/host/port
udp/host/port
EXAMPLES:
`basename
$0
` If no param is given it checks entries in
$cfgfile
`basename
$0
` -t "tcp/api.example.com/443"
Check a single connection
`basename
$0
` -t "tcp/api.example.com/443 tcp/localhost/3306"
Check multiple connections.
EOF
}
# ----------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------
# --- check required tools
# ph.require bc top
# --- check param -h
case
"
$1
"
in
"--help"
|
"-h"
)
showHelp
exit
0
;;
*
)
esac
configline
=
$(
ph.getValueWithParam
""
t
"
$@
"
)
test
-z
"
$configline
"
||
cfgfile
=
""
typeset
-i
iWarnings
=
0
typeset
-i
iErrors
=
0
typeset
-i
iOK
=
0
typeset
-i
iCount
=
0
for
myline
in
$(
echo
$configline
;
getChecks
$cfgfile
)
do
iCount
=
$iCount
+1
out
=
"
$out
$myline
"
# --- syntax check of config entry
echo
"
$myline
"
|
grep
-E
"^(tcp|udp)/[a-z][a-z0-9
\.\-
]*/[0-9]*$"
>
/dev/null 2>&1
if
[
$?
-ne
0
]
;
then
out
=
"
$out
SKIP: INVALID ENTRY"
iWarnings
=
$iWarnings
+1
else
>
/dev/
$myline
if
[
$?
-ne
0
]
;
then
out
=
"
$out
FAILED"
iErrors
=
$iErrors
+1
else
out
=
"
$out
OK"
iOK
=
$iOK
+1
fi
fi
done
# ----- output
if
[
$iCount
-eq
0
]
;
then
ph.setStatus
"unknown"
ph.status
"tcp check - NO checks"
test
$iCount
-eq
0
&&
echo
"
No config entry was found. Create a file named
$cfgfile
and add your connections i.e.
tcp/www.example.com/443"
else
test
$iWarnings
-gt
0
&&
ph.setStatus
"warning"
test
$iErrors
-gt
0
&&
ph.setStatus
"critical"
ph.status
"tcp check -
$iCount
checks -
$iOK
OK;
$iWarnings
warnings;
$iErrors
errors
$out
"
fi
# ----- CLEANUP AND BYE!
ph.exit
# ----------------------------------------------------------------------
This diff is collapsed.
Click to expand it.
check_conn.cfg.dist
0 → 100644
+
19
−
0
View file @
f3518944
# ----------------------------------------------------------------------
#
# This is an example file for check_tcp
# You need to rename it and then make your changes.
#
# lines not starting with tcp or udp will be ignored. So feel free
# to use # or ; as commented lines or add empty lines for spacing.
#
# ----------------------------------------------------------------------
# check if a needed api server is reachable
tcp/api.example.com/80
tcp/api.example.com/443
# check local mysql port
tcp/localhost/3306
# ----------------------------------------------------------------------
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