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
9f1b6c82
Commit
9f1b6c82
authored
2 years ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
shellfix corrections
parent
a07c7b92
Branches
Branches containing commit
No related tags found
1 merge request
!37
5665 packages2install fix yum
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
inc_pluginfunctions
+34
-29
34 additions, 29 deletions
inc_pluginfunctions
with
34 additions
and
29 deletions
inc_pluginfunctions
+
34
−
29
View file @
9f1b6c82
...
...
@@ -29,6 +29,7 @@
# 2019-10-29 added setExitcode
# 2020-03-05 v1.2 <axel.hahn@iml.unibe.ch> switch to ph.* helper functions
# 2020-09-01 v1.3 <axel.hahn@iml.unibe.ch> added ph.hasParamoption
# 2022-08-31 v1.4 <axel.hahn@iml.unibe.ch> shellfix corrections
# ======================================================================
...
...
@@ -49,7 +50,7 @@ ph_cmd__params="$@"
# abort a check and exit with status "unknown"
function
ph.abort
(){
ph.setStatus
"unknown"
echo
$*
echo
"
$*
"
ph.exit
}
...
...
@@ -77,20 +78,20 @@ function ph.exit(){
# detect LINUX DISTRO as lowercase
# returns one of centos|debian|ubuntu|...
function
ph.getOS
(){
distro
=
local
distro
=
if
[
-z
$distro
]
;
then
# centos7, debian, manjaro, ubuntu
distro
=
`
cat
/etc/
*
-release
|
grep
"^ID="
|
cut
-f
2
-d
"="
`
distro
=
$(
grep
"^ID="
/etc/
*
-release
|
cut
-f
2
-d
"="
)
fi
if
[
-z
$distro
]
;
then
# debian6,7, ubuntu 10,12 .. maybe unneeded.
distro
=
`
cat
/etc/issue |
head
-1
|
grep
"^[a-zA-Z]"
|
cut
-f
1
-d
" "
`
distro
=
$(
head
-1
/etc/issue |
grep
"^[a-zA-Z]"
|
cut
-f
1
-d
" "
)
fi
# sanitize: lowercase, remove "
distro
=
`
echo
$distro
|
tr
-d
'"'
|
tr
[
:upper:]
[
:lower:]
`
distro
=
$(
echo
$distro
|
tr
-d
'"'
|
tr
[
:upper:]
[
:lower:]
)
if
[
-z
$distro
]
;
then
ph.abort
"UNKNOWN: distro was not detected."
...
...
@@ -104,12 +105,12 @@ function ph.getOS(){
# returns an integer, i.e. 7 on CentOS7
function
ph.getOSMajor
(){
local
_version
=
_version
=
`
cat
/etc/
*
-release
| e
grep
"^(VERSION_ID|DISTRIB_RELEASE)="
|
head
-1
|
cut
-f
2
-d
"="
|
sed
's#"##g'
|
cut
-f
1
-d
"."
`
_version
=
$(
grep
-E
"^(VERSION_ID|DISTRIB_RELEASE)="
/etc/
*
-release
|
head
-1
|
cut
-f
2
-d
"="
|
sed
's#"##g'
|
cut
-f
1
-d
"."
)
if
[
-z
"
$_version
"
]
;
then
_version
=
"?"
exit
1
fi
echo
$_version
echo
"
$_version
"
}
# helper to use the default _value or override it with a found param
...
...
@@ -136,7 +137,7 @@ function ph.getValueWithParam(){
;;
esac
done
echo
$_value
echo
"
$_value
"
}
# check if a letter was used as command line option and return as 0 (=no) or 1 (=yes)
...
...
@@ -159,7 +160,7 @@ function ph.hasParamoption(){
while
getopts
"abcdefghijklmnopqrstuvwxyz"
_opt
;
do
# echo "DEBUG: testing $_sParam in ${_opt} ..."
case
"
${
_opt
}
"
in
$_sParam
)
"
$_sParam
"
)
echo
"1"
return
1
;;
...
...
@@ -255,7 +256,8 @@ function ph.status(){
# example: 12M returns 2^30 from ending "M"
# param value with ending scale [none]=1 K=Kilo M=Mega G=Giga
function
ph._getExp
(){
local
_unit
=
`
echo
$1
|
sed
"s#[0-9]##g"
`
local
_unit
_unit
=
$(
echo
$1
|
sed
"s#[0-9]##g"
)
test
-z
"
$_unit
"
&&
echo
1
...
...
@@ -311,14 +313,17 @@ function ph.getFileAge(){
echo
$((
$(
date
+%s
)
-
$(
date
+%s
-r
"
$1
"
)
))
}
# get file for storage of last value
# global string dir_data custom path; default is /tmp/icinga_counter/
function
ph._getStorefile
(){
local
varName
=
$1
local
mydir
=
"/tmp/icinga_counter"
test
-z
$dir_data
||
mydir
=
"
${
dir_data
}
/_counter"
local
_basename
=
`
basename
$0
`
test
-n
"
$dir_data
"
&&
mydir
=
"
${
dir_data
}
/_counter"
local
_basename
_basename
=
$(
basename
$0
)
test
-d
${
mydir
}
||
mkdir
-p
${
mydir
}
test
-d
"
${
mydir
}
"
||
mkdir
-p
"
${
mydir
}
"
echo
"
${
mydir
}
/
${
_basename
}${
varName
}
.lastvalue"
}
...
...
@@ -327,7 +332,7 @@ function ph._getStorefile(){
function
ph._savecounter
()
{
local
varName
=
$1
local
value
=
$2
local
sStoreFile
=
`
ph._getStorefile
"
${
varName
}
"
`
local
sStoreFile
=
$(
ph._getStorefile
"
${
varName
}
"
)
#echo "DEBUG: `date +%s`:${value} \> ${sStoreFile}"
# echo "`date +%s`:${value}" > "${sStoreFile}"
echo
${
value
}
>
"
${
sStoreFile
}
"
...
...
@@ -335,7 +340,7 @@ function ph._savecounter() {
function
ph._getageoflastvalue
()
{
local
varName
=
$1
local
sStoreFile
=
`
ph._getStorefile
"
${
varName
}
"
`
local
sStoreFile
=
$(
ph._getStorefile
"
${
varName
}
"
)
ph.getFileAge
"
${
sStoreFile
}
"
# local ilast=`cat "${sStoreFile}" 2>/dev/null | cut -f 1 -d ":" `
# local inow=`date +%s`
...
...
@@ -343,7 +348,7 @@ function ph._getageoflastvalue() {
}
function
ph._readlastvalue
(){
local
varName
=
$1
local
sStoreFile
=
`
ph._getStorefile
"
${
varName
}
"
`
local
sStoreFile
=
$(
ph._getStorefile
"
${
varName
}
"
)
# cat "${sStoreFile}" 2>/dev/null | cut -f 2 -d ":"
cat
"
${
sStoreFile
}
"
2>/dev/null
}
...
...
@@ -351,14 +356,15 @@ function ph._readlastvalue(){
# init usage for performance data
# it creates a filename based on the started check script
function
ph._perfinit
(){
local
_basename
=
`
basename
$0
`
ph_perfdatafile
=
"/tmp/perfdata_
`
echo
$_basename
|
sed
"s#[^a-z0-9
\-
]#_#g"
`
"
local
_basename
_basename
=
$(
basename
$0
)
ph_perfdatafile
=
"/tmp/perfdata_
$(
echo
$_basename
|
sed
"s#[^a-z0-9
\-
]#_#g"
)
"
rm
-f
"
${
ph_perfdatafile
}
"
2>/dev/null
}
# generate label for performance data value
function
ph._getperflabel
(){
echo
$1
|
tr
[
:upper:]
[
:lower:] |
sed
"s#[^a-z0-9
\-
]##g"
echo
"
$1
"
|
tr
[
:upper:]
[
:lower:] |
sed
"s#[^a-z0-9
\-
]##g"
}
# get speed of change of a counter value
# param1: string variable name
...
...
@@ -371,7 +377,6 @@ function ph.perfdeltaspeed(){
local
bcParam
=
typeset
-i
newvalue
=
0
typeset
-i
deltaFactor
=
1
test
"
$deltaUnit
"
=
"s"
&&
deltaFactor
=
1
...
...
@@ -382,7 +387,7 @@ function ph.perfdeltaspeed(){
test
"
$isFloat
"
=
"float"
&&
bcParam
=
"-l"
# get last value
local
lastvalue
=
`
ph._readlastvalue
"
${
varName
}
"
`
local
lastvalue
=
$(
ph._readlastvalue
"
${
varName
}
"
)
if
[
"
$lastvalue
"
=
""
]
;
then
# retvalue="[no last value]"
retvalue
=
""
...
...
@@ -395,11 +400,11 @@ function ph.perfdeltaspeed(){
# retvalue="[reset data]"
retvalue
=
""
else
local
iage
=
`
ph._getageoflastvalue
"
${
varName
}
"
`
local
iage
=
$(
ph._getageoflastvalue
"
${
varName
}
"
)
test
$iage
=
0
&&
iage
=
1
local
delta
=
`
echo
"
${
value
}
-
$lastvalue
"
| bc
$bcParam
`
local
deltaspeed
=
`
echo
"
${
delta
}
*
${
deltaFactor
}
/(
${
iage
}
)"
| bc
$bcParam
`
local
delta
=
$(
echo
"
${
value
}
-
$lastvalue
"
| bc
$bcParam
)
local
deltaspeed
=
$(
echo
"
${
delta
}
*
${
deltaFactor
}
/(
${
iage
}
)"
| bc
$bcParam
)
retvalue
=
$deltaspeed
fi
fi
...
...
@@ -407,7 +412,7 @@ function ph.perfdeltaspeed(){
#echo DEBUG sData="${sData} '${varName}'=${retvalue}"
# sGDData="${sGDData} '${varName}'=${retvalue}"
echo
${
retvalue
}
echo
"
${
retvalue
}
"
# DEBUG - wird in Nagios sichtbar
# gdAddLabel "... ${varName} absolute: ${value} -> delta: ${delta} -> derive: ${retvalue} ($iage sec)"
...
...
@@ -425,7 +430,7 @@ function ph.perfadd(){
if
[
-z
"
$ph_perfdatafile
"
]
;
then
ph._perfinit
fi
local
_label
=
`
ph._getperflabel
"
$1
"
`
local
_label
=
$(
ph._getperflabel
"
$1
"
)
local
_value
=
$2
local
_w
=
$3
local
_c
=
$4
...
...
@@ -435,7 +440,7 @@ function ph.perfadd(){
if
[
-z
"
$_min
"
]
;
then
_min
=
0
fi
echo
"
${
_label
}
=
${
_value
}
;
${
_w
}
;
${
_c
}
;
${
_min
}
;
${
_max
}
"
>>
${
ph_perfdatafile
}
echo
"
${
_label
}
=
${
_value
}
;
${
_w
}
;
${
_c
}
;
${
_min
}
;
${
_max
}
"
>>
"
${
ph_perfdatafile
}
"
}
...
...
@@ -445,8 +450,8 @@ function ph.perfshow(){
if
[
!
-z
"
$ph_perfdatafile
"
]
;
then
if
[
-f
"
$ph_perfdatafile
"
]
;
then
echo
-n
" |"
cat
${
ph_perfdatafile
}
|
tr
"
\n
"
" "
rm
-f
${
ph_perfdatafile
}
cat
"
${
ph_perfdatafile
}
"
|
tr
"
\n
"
" "
rm
-f
"
${
ph_perfdatafile
}
"
fi
fi
}
...
...
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