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
36a30c40
Commit
36a30c40
authored
1 year ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
fix ph.toUnit with float values; shell fixes
parent
21206833
No related branches found
No related tags found
1 merge request
!122
Update docs
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
inc_pluginfunctions
+23
-26
23 additions, 26 deletions
inc_pluginfunctions
with
23 additions
and
26 deletions
inc_pluginfunctions
+
23
−
26
View file @
36a30c40
...
...
@@ -36,6 +36,7 @@
# 2023-04-24 v1.8 <axel.hahn@unibe.ch> fix unit conversion
# 2023-05-05 v1.9 <axel.hahn@unibe.ch> user specific counter directory
# 2023-05-17 v1.10 <axel.hahn@unibe.ch> ph.getOS searches in os-release first
# 2023-06-22 v1.11 <axel.hahn@unibe.ch> fix ph.toUnit with float values; shell fixes
# ======================================================================
...
...
@@ -45,13 +46,9 @@ typeset -i ph_cfg__EXIT_WARNING=1
typeset
-i
ph_cfg__EXIT_CRITICAL
=
2
typeset
-i
ph_cfg__EXIT_UNKNOWN
=
3
declare
ph_perfdatafile
=
# declare -a ph_perfdata
typeset
-i
ph_perfcounter
=
0
# save command line params
ph_cmd__params
=
"
$@
"
typeset
-i
ph_cfg__EXIT_CODE
declare
ph_perfdatafile
=
# abort a check and exit with status "unknown"
function
ph.abort
(){
...
...
@@ -86,24 +83,24 @@ function ph.exit(){
function
ph.getOS
(){
local
distro
=
if
[
-z
$distro
]
;
then
if
[
-z
"
$distro
"
]
;
then
# centos7, debian, manjaro, ubuntu
distro
=
$(
grep
"^ID="
/etc/os-release |
cut
-f
2
-d
"="
)
fi
if
[
-z
$distro
]
;
then
if
[
-z
"
$distro
"
]
;
then
distro
=
$(
grep
"^ID="
/etc/
*
-release
|
cut
-f
2
-d
"="
)
fi
if
[
-z
$distro
]
;
then
if
[
-z
"
$distro
"
]
;
then
# debian6,7, ubuntu 10,12 .. maybe unneeded.
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
if
[
-z
"
$distro
"
]
;
then
ph.abort
"UNKNOWN: distro was not detected."
fi
...
...
@@ -190,19 +187,19 @@ function ph.hasParamoption(){
# param integer|string 0..3 or ok|warning|critical|unknown
function
ph.setStatus
(){
case
$1
in
$ph_cfg__EXIT_OK
|
"ok"
)
:
"
$ph_cfg__EXIT_OK
"
|
"ok"
)
:
ph_cfg__EXIT_CODE
=
$ph_cfg__EXIT_OK
ph_cfg__EXIT_STATUS
=
"OK"
;;
$ph_cfg__EXIT_WARNING
|
"warning"
)
:
"
$ph_cfg__EXIT_WARNING
"
|
"warning"
)
:
ph_cfg__EXIT_CODE
=
$ph_cfg__EXIT_WARNING
ph_cfg__EXIT_STATUS
=
"WARNING"
;;
$ph_cfg__EXIT_CRITICAL
|
"critical"
)
:
"
$ph_cfg__EXIT_CRITICAL
"
|
"critical"
)
:
ph_cfg__EXIT_CODE
=
$ph_cfg__EXIT_CRITICAL
ph_cfg__EXIT_STATUS
=
"CRITICAL"
;;
$ph_cfg__EXIT_UNKNOWN
|
"unknown"
)
:
"
$ph_cfg__EXIT_UNKNOWN
"
|
"unknown"
)
:
ph_cfg__EXIT_CODE
=
$ph_cfg__EXIT_UNKNOWN
ph_cfg__EXIT_STATUS
=
"UNKNOWN"
;;
...
...
@@ -267,7 +264,7 @@ function ph.status(){
# param value with ending scale [none]=1 K=Kilo M=Mega G=Giga
function
ph._getExp
(){
local
_unit
_unit
=
$
(
echo
$1
|
sed
"s#[0-9]##g"
)
_unit
=
$
{
1
//[0-9\.]/
}
test
-z
"
$_unit
"
&&
echo
1
...
...
@@ -300,11 +297,11 @@ function ph.toUnit(){
local
_value
=
$1
local
_unit
=
$2
local
_multiply
=
`
ph._getExp
$_value
`
local
_divisor
=
`
ph._getExp
$_unit
`
local
_multiply
;
_multiply
=
$(
ph._getExp
"
$_value
"
)
local
_divisor
;
_divisor
=
$(
ph._getExp
"
$_unit
"
)
# echo "DEBUG ... $_divisor .. $_multiply"
echo
"
$(
echo
$_value
|
tr
-d
"[:alpha:]"
)
*
${
_multiply
}
/
$_divisor
"
| bc
echo
"
$(
echo
"
$_value
"
|
tr
-d
"[:alpha:]"
)
*
${
_multiply
}
/
$_divisor
"
| bc
}
...
...
@@ -346,7 +343,7 @@ function ph._getStorefile(){
function
ph._savecounter
()
{
local
varName
=
$1
local
value
=
$2
local
sStoreFile
=
$(
ph._getStorefile
"
${
varName
}
"
)
local
sStoreFile
;
sStoreFile
=
$(
ph._getStorefile
"
${
varName
}
"
)
#echo "DEBUG: `date +%s`:${value} \> ${sStoreFile}"
# echo "`date +%s`:${value}" > "${sStoreFile}"
echo
${
value
}
>
"
${
sStoreFile
}
"
...
...
@@ -357,7 +354,7 @@ function ph._savecounter() {
# param string varName variable name of a value to store
function
ph._getageoflastvalue
()
{
local
varName
=
$1
local
sStoreFile
=
$(
ph._getStorefile
"
${
varName
}
"
)
local
sStoreFile
;
sStoreFile
=
$(
ph._getStorefile
"
${
varName
}
"
)
ph.getFileAge
"
${
sStoreFile
}
"
# local ilast=`cat "${sStoreFile}" 2>/dev/null | cut -f 1 -d ":" `
# local inow=`date +%s`
...
...
@@ -368,7 +365,7 @@ function ph._getageoflastvalue() {
# param string varName variable name of a value to store
function
ph._readlastvalue
(){
local
varName
=
$1
local
sStoreFile
=
$(
ph._getStorefile
"
${
varName
}
"
)
local
sStoreFile
;
sStoreFile
=
$(
ph._getStorefile
"
${
varName
}
"
)
# cat "${sStoreFile}" 2>/dev/null | cut -f 2 -d ":"
cat
"
${
sStoreFile
}
"
2>/dev/null
}
...
...
@@ -420,11 +417,11 @@ function ph.perfdeltaspeed(){
# retvalue="[reset data]"
retvalue
=
""
else
local
iage
=
$(
ph._getageoflastvalue
"
${
varName
}
"
)
test
$iage
=
0
&&
iage
=
1
local
iage
;
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
;
delta
=
$(
echo
"
${
value
}
-
$lastvalue
"
| bc
$bcParam
)
local
deltaspeed
;
deltaspeed
=
$(
echo
"
${
delta
}
*
${
deltaFactor
}
/(
${
iage
}
)"
| bc
$bcParam
)
retvalue
=
$deltaspeed
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