Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
icinga-passive-client
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
Open Source
icinga-passive-client
Commits
68fa2cb1
Commit
68fa2cb1
authored
4 years ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
add --load to override local host config
parent
d40865bb
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
_etc/client.cfg.dist
+4
-2
4 additions, 2 deletions
_etc/client.cfg.dist
director-cli.sh
+62
-35
62 additions, 35 deletions
director-cli.sh
inc_functions.sh
+14
-5
14 additions, 5 deletions
inc_functions.sh
plugins
+1
-1
1 addition, 1 deletion
plugins
with
81 additions
and
43 deletions
_etc/client.cfg.dist
+
4
−
2
View file @
68fa2cb1
...
@@ -24,10 +24,12 @@
...
@@ -24,10 +24,12 @@
#
#
selfname="icinga2-passive-client"
selfname="icinga2-passive-client"
# directory of config files for api profiles and defined
# directory of config files for api profiles
# checks
dir_cfg="/etc/${selfname}"
dir_cfg="/etc/${selfname}"
# directory of defined checks
dir_checks="/etc/${selfname}/checks"
# tmp data of checks, i.e. to keep last output
# tmp data of checks, i.e. to keep last output
dir_data="/var/tmp/${selfname}"
dir_data="/var/tmp/${selfname}"
...
...
This diff is collapsed.
Click to expand it.
director-cli.sh
+
62
−
35
View file @
68fa2cb1
...
@@ -22,26 +22,23 @@
...
@@ -22,26 +22,23 @@
tmpfile
=
/tmp/outcurl.tmp
tmpfile
=
/tmp/outcurl.tmp
tmpfile2
=
/tmp/outcurl2.tmp
tmpfile2
=
/tmp/outcurl2.tmp
APICLIENT
=
`
dirname
$0
`
/api2director
# a custom file to source instead of detecting local data
loadfile
=
# UNUSED
# APICLIENT=`dirname $0`/api2director
# MY_NAME=`facter fqdn | cut -f -2 -d ">"`
# MY_NAME=`facter fqdn | cut -f -2 -d ">"`
# MY_IP=`facter ipaddress | cut -f -2 -d ">"`
# MY_IP=`facter ipaddress | cut -f -2 -d ">"`
MY_NAME
=
`
hostname
-f
`
# TODO: test ... maybe uncomment it again
MY_IP
=
`
_getIpFrontend
`
# MY_NAME=`hostname -f`
# MY_IP=`_getIpFrontend`
typeset
cfg_debug
=
false
typeset
cfg_debug
=
false
typeset
cfg_dryrun
=
false
typeset
cfg_dryrun
=
false
ch
=
"
`
dirname
$0
`
/inc/confighandler.sh"
IDC_host__cachefile
=
"
${
dir_data
}
/host_
${
MY_NAME
}
__at-director.txt"
IDC_service__cachefile
=
"
${
dir_data
}
/all_defined_services__at-director.txt"
IDC_svcathost__cachefile
=
"
${
dir_data
}
/services_on_host__at-director.txt"
# ======================================================================
# ======================================================================
#
#
# FUNCTIONS
# FUNCTIONS
...
@@ -58,6 +55,17 @@ IDC_svcathost__cachefile="${dir_data}/services_on_host__at-director.txt"
...
@@ -58,6 +55,17 @@ IDC_svcathost__cachefile="${dir_data}/services_on_host__at-director.txt"
fi
fi
}
}
function
_initVars
(){
if
[
-z
"
$loadfile
"
]
;
then
MY_NAME
=
`
hostname
-f
`
MY_IP
=
`
_getIpFrontend |
head
-1
`
fi
IDC_host__cachefile
=
"
${
dir_data
}
/
${
MY_NAME
}
__host_at-director.txt"
IDC_service__cachefile
=
"
${
dir_data
}
/
${
MY_NAME
}
__all_defined_services__at-director.txt"
IDC_svcathost__cachefile
=
"
${
dir_data
}
/
${
MY_NAME
}
__services_on_host__at-director.txt"
# ch="`dirname $0`/inc/confighandler.sh"
ch
=
"./inc/confighandler.sh"
}
function
flushDatadir
(){
function
flushDatadir
(){
if
[
!
-z
"
${
dir_data
}
"
-a
-d
"
${
dir_data
}
"
]
;
then
if
[
!
-z
"
${
dir_data
}
"
-a
-d
"
${
dir_data
}
"
]
;
then
...
@@ -72,18 +80,17 @@ IDC_svcathost__cachefile="${dir_data}/services_on_host__at-director.txt"
...
@@ -72,18 +80,17 @@ IDC_svcathost__cachefile="${dir_data}/services_on_host__at-director.txt"
# ............................................................
# ............................................................
# set $ch to store all object vars
# set $ch to store all object vars
function
_generateJsonForHost
(){
function
_generateJsonForHost
(){
# --- host infos
if
[
-z
"
$loadfile
"
]
;
then
# local MY_OSName=`facter os -y | grep " distid:" | cut -f 2 -d ":" | cut -f 2 -d " " | tr '[:upper:]' '[:lower:]'`
# --- host infos
# local MY_OSMajorVersion=`facter os -y | grep " majdistrelease:" | cut -f 2 -d ":" | cut -f 2 -d "'"`
#
local MY_Platform=`
facter kernel | tr '[:upper:]' '[:lower:]
'`
local
MY_Platform
=
`
uname
-a
|
cut
-f
1
-d
'
'
`
local
MY_Platform
=
`
uname
-a
|
cut
-f
1
-d
' '
`
.
`
dirname
$0
`
/plugins/inc_pluginfunctions
||
exit
1
.
`
dirname
$0
`
/plugins/inc_pluginfunctions
local
MY_OSName
=
`
ph.getOS
`
local
MY_OS
Name
=
`
ph.getOS
`
local
MY_OS
MajorVersion
=
`
ph.getOS
Major
`
local
MY_OSMajorVersion
=
`
ph.getOSMajor
`
fi
export
CFGSTORAGE
=
"directorhost"
export
CFGSTORAGE
=
"directorhost"
(
(
...
@@ -95,7 +102,7 @@ IDC_svcathost__cachefile="${dir_data}/services_on_host__at-director.txt"
...
@@ -95,7 +102,7 @@ IDC_svcathost__cachefile="${dir_data}/services_on_host__at-director.txt"
$ch
--set
icon_image
\"
/images/os/
${
MY_OSName
}
.png
\"
$ch
--set
icon_image
\"
/images/os/
${
MY_OSName
}
.png
\"
$ch
--set
icon_image_alt
\"
${
MY_Platform
}
\:\
${
MY_OSName
}
\
${
MY_OSMajorVersion
}
\"
$ch
--set
icon_image_alt
\"
${
MY_Platform
}
\:\
${
MY_OSName
}
\
${
MY_OSMajorVersion
}
\"
)
2>/dev/null
)
2>/dev/null
# --- detect phase
# --- detect phase
# local phase="live"
# local phase="live"
...
@@ -111,19 +118,19 @@ IDC_svcathost__cachefile="${dir_data}/services_on_host__at-director.txt"
...
@@ -111,19 +118,19 @@ IDC_svcathost__cachefile="${dir_data}/services_on_host__at-director.txt"
# ----- set host type
# ----- set host type
# host in the UNIBE network:
# host in the UNIBE network:
echo
$MY_IP
|
grep
"^130.92"
>
/dev/null
&&
(
echo
$MY_IP
|
grep
-E
"^(10
\.
|172
\.
1[6-9]
\.
|172.2[0-9]
\.
|172
\.
3[01]
\.
|192.168
\.
)"
>
/dev/null
$ch
--set
imports
'["host in network"]'
if
[
$?
-eq
0
]
;
then
$ch
--set
imports
'["host passive only"]'
# port checks initiated by icinga server to monitor client
else
if
[
!
-z
"
${
host_vars_tcpport
}
"
-a
"
${
host_vars_tcpport
}
"
!=
"[]"
]
;
then
$ch
--set
imports
'["host in network"]'
host_vars_tcpport
=
`
echo
${
host_vars_tcpport
}
|
sed
"s# ##g"
`
$ch
--set
vars.tcp_port
${
host_vars_tcpport
}
fi
)
# ONE private network
# port checks initiated by icinga server to monitor client
echo
$MY_IP
|
grep
"^10
\.
"
>
/dev/null
&&
$ch
--set
imports
'["host passive only"]'
if
[
!
-z
"
${
host_vars_tcpport
}
"
-a
"
${
host_vars_tcpport
}
"
!=
"[]"
]
;
then
host_vars_tcpport
=
`
echo
${
host_vars_tcpport
}
|
sed
"s# ##g"
`
$ch
--set
vars.tcp_port
${
host_vars_tcpport
}
fi
fi
# ----- /host type
# ----- /host type
...
@@ -411,7 +418,8 @@ IDC_svcathost__cachefile="${dir_data}/services_on_host__at-director.txt"
...
@@ -411,7 +418,8 @@ IDC_svcathost__cachefile="${dir_data}/services_on_host__at-director.txt"
# ............................................................
# ............................................................
# helper to create a base config for the current host
# helper to create a base config for the current host
function
_initHostdata
(){
# UNUSED
function
UNUSED_initHostdata
(){
export
CFGSTORAGE
=
"directorhost"
export
CFGSTORAGE
=
"directorhost"
(
(
$ch
--flush
$ch
--flush
...
@@ -754,6 +762,9 @@ echo
...
@@ -754,6 +762,9 @@ echo
cd
`
dirname
$0
`
cd
`
dirname
$0
`
ls
./
`
basename
$0
`
>
/dev/null
||
exit
1
ls
./
`
basename
$0
`
>
/dev/null
||
exit
1
_initVars
# ensure that ./inc_getconfig.sh was loaded
# ensure that ./inc_getconfig.sh was loaded
if
[
-z
"
${
dir_cfg
}
"
]
;
then
if
[
-z
"
${
dir_cfg
}
"
]
;
then
echo
ERROR: Client is not installed/ configured yet on this machine.
echo
ERROR: Client is not installed/ configured yet on this machine.
...
@@ -786,6 +797,18 @@ do
...
@@ -786,6 +797,18 @@ do
'--dryrun'
)
'--dryrun'
)
cfg_dryrun
=
true
cfg_dryrun
=
true
;;
;;
# ----- override local data with those from a file
'--load'
)
if
[
!
-f
"
$2
"
]
;
then
echo
ERROR: file
"
$2
"
is not readable.
echo
Hint: ist must be an absolute path or relative to
$(
pwd
)
exit
1
fi
loadfile
=
"
$2
"
.
"
${
loadfile
}
"
shift
echo
"loaded
${
loadfile
}
"
;;
# ----- host actions
# ----- host actions
...
@@ -804,6 +827,10 @@ do
...
@@ -804,6 +827,10 @@ do
'--hd'
|
'--hostdelete'
)
'--hd'
|
'--hostdelete'
)
hostDelete
hostDelete
;;
;;
'--hs'
|
'--hostshow'
)
_generateJsonForHost
$ch
--json
2>/dev/null
;;
# ----- check actions
# ----- check actions
...
...
This diff is collapsed.
Click to expand it.
inc_functions.sh
+
14
−
5
View file @
68fa2cb1
...
@@ -63,12 +63,21 @@
...
@@ -63,12 +63,21 @@
# get a list of config file of all checks to execute
# get a list of config file of all checks to execute
# no params
# no params
function
getChecks
(){
function
getChecks
(){
if
[
-d
${
dir_cfg
}
/checks/
]
;
then
if
[
-z
"
${
dir_checks
}
"
]
;
then
for
myconfig
in
`
ls
-1
${
dir_cfg
}
/checks/
*
`
echo
"ERROR: config dir for checks is empty."
do
echo
"Verify value of dir_checks in
$dir_cfg
/client.cfg"
echo
${
myconfig
}
exit
1
done
fi
fi
if
[
!
-d
${
dir_checks
}
]
;
then
echo
"ERROR: config dir for checks dir_checks does not exist:
$dir_checks
"
exit
1
fi
for
myconfig
in
`
ls
-1
${
dir_checks
}
/
*
`
do
echo
${
myconfig
}
done
}
}
# parse a config file and set global vars:
# parse a config file and set global vars:
...
...
This diff is collapsed.
Click to expand it.
plugins
@
1dfbc60f
Subproject commit
3434a495ba0f558aa327b79ca5eae44c5d0ca6b6
Subproject commit
1dfbc60f30f390ea65471fb383525e0ec8c5cb94
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