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
eb869f29
Commit
eb869f29
authored
2 years ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
fix netstat; shell fixes; no tmpfiles; IML look
parent
9876037c
No related branches found
No related tags found
1 merge request
!50
Fix netstat
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
check_netstat
+63
-26
63 additions, 26 deletions
check_netstat
with
63 additions
and
26 deletions
check_netstat
+
63
−
26
View file @
eb869f29
...
...
@@ -8,12 +8,50 @@
#
# ----------------------------------------------------------------------
# 2020-07-08 v1.0 <axel.hahn@iml.unibe.ch>
# 2022-10-25 v1.1 <axel.hahn@unibe.ch> shell fixes; no tmpfiles; IML look
# ======================================================================
.
`
dirname
$0
`
/inc_pluginfunctions
.
$(
dirname
$0
)
/inc_pluginfunctions
self_APPNAME
=
$(
basename
$0
|
tr
[
:lower:]
[
:upper:]
)
self_APPVERSION
=
1.1
# ----------------------------------------------------------------------
# functions
# ----------------------------------------------------------------------
function
showHelp
(){
cat
<<
EOF
______________________________________________________________________
$self_APPNAME
v
$self_APPVERSION
(c) Institute for Medical Education - University of Bern
Licence: GNU GPL 3
______________________________________________________________________
Count number of network connections.
SYNTAX:
$(
basename
$0
)
[ -w value -c value -h ]
-w VALUE cpu usage warning level (default: 75)
-c VALUE cpu usage critical level (default: 90)
-h or --help show this help.
PARAMETERS:
None.
EXAMPLE:
$(
basename
$0
)
-w 60 -c 80 -p 40
If there is no -w and -c then the result is always OK.
EOF
}
# ----------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------
...
...
@@ -22,32 +60,28 @@
ph.require netstat
# --- check param -h
if
[
"
$1
"
=
"-h"
]
;
then
echo
"
usage:
$0
[ -w value -c value -h ]
-w Warning count (optional)
-c Critical count (optional; must be larger than warning)
-h this help
If there is no -w and -c then the result is always OK.
"
exit
0
fi
case
"
$1
"
in
"--help"
|
"-h"
)
showHelp
exit
0
;;
*
)
esac
# --- set optional limits
typeset
-i
iWarnLimit
=
`
ph.getValueWithParam 0 w
"
$@
"
`
typeset
-i
iCriticalLimit
=
`
ph.getValueWithParam 0 c
"
$@
"
`
typeset
-i
iWarnLimit
=
$(
ph.getValueWithParam 0 w
"
$@
"
)
typeset
-i
iCriticalLimit
=
$(
ph.getValueWithParam 0 c
"
$@
"
)
# --- count all connections
tmpfile1
=
`
mktemp
`
tmpfile
=
`
mktemp
`
typeset
-i
iTotal
=
0
typeset
-i
iEst
=
0
typeset
-i
iListen
=
0
typeset
-i
iWait
=
0
(
netstat
-wltun
;
netstat
-wtun
)
|
awk
'{ print $6 }'
|
grep
-E
'(ESTABLISHED|LISTEN|TIME_WAIT)'
>
$tmpfile1
typeset
-i
iTotal
=
`
wc
-l
$tmpfile1
|
awk
'{ print $1 }'
`
netdata
=
$(
(
netstat
-wltun
;
netstat
-wtun
)
|
awk
'{ print $6 }'
|
grep
-E
'(ESTABLISHED|LISTEN|TIME_WAIT)'
)
iTotal
=
$(
echo
"
$netdata
"
|
wc
-l
|
awk
'{ print $1 }'
)
if
[
$iWarnLimit
-gt
0
-a
$iCriticalLimit
-gt
0
]
;
then
if
[
$iWarnLimit
-gt
0
-a
$iCriticalLimit
-gt
0
]
;
then
ph.setStatusByLimit
$iTotal
$iWarnLimit
$iCriticalLimit
fi
...
...
@@ -55,17 +89,20 @@ ph.status "NETSTAT - count of connections: $iTotal"
# --- add performance data
c
at
$tmpfile1
|
sort
|
uniq
-c
>
$tmpfile
d
at
a2
=
$(
echo
"
$netdata
"
|
sort
|
uniq
-c
)
# result is something like that:
# 5 ESTABLISHED
# 10 LISTEN
# 77 TIME_WAIT
echo
"
$data2
"
ph.perfadd
"established"
"
`
grep
ESTABLISHED
$tmpfile
|
awk
'{ print $1 }'
`
"
ph.perfadd
"listen"
"
`
grep
LISTEN
$tmpfile
|
awk
'{ print $1 }'
`
"
ph.perfadd
"time-wait"
"
`
grep
TIME_WAIT
$tmpfile
|
awk
'{ print $1 }'
`
"
iEst
=
$(
echo
"
$data2
"
|
grep
ESTABLISHED |
awk
'{ print $1 }'
)
iListen
=
$(
echo
"
$data2
"
|
grep
LISTEN |
awk
'{ print $1 }'
)
iWait
=
$(
echo
"
$data2
"
|
grep
TIME_WAIT |
awk
'{ print $1 }'
)
ph.perfadd
"established"
"
$iEst
"
ph.perfadd
"listen"
"
$iListen
"
ph.perfadd
"time-wait"
"
$iWait
"
# --- bye
rm
-f
$tmpfile
$tmpfile1
ph.exit
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