Skip to content
Snippets Groups Projects
Commit 68fa2cb1 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

add --load to override local host config

parent d40865bb
No related branches found
No related tags found
No related merge requests found
......@@ -24,10 +24,12 @@
#
selfname="icinga2-passive-client"
# directory of config files for api profiles and defined
# checks
# directory of config files for api profiles
dir_cfg="/etc/${selfname}"
# directory of defined checks
dir_checks="/etc/${selfname}/checks"
# tmp data of checks, i.e. to keep last output
dir_data="/var/tmp/${selfname}"
......
......@@ -22,26 +22,23 @@
tmpfile=/tmp/outcurl.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_IP=`facter ipaddress | cut -f -2 -d ">"`
MY_NAME=`hostname -f`
MY_IP=`_getIpFrontend`
# TODO: test ... maybe uncomment it again
# MY_NAME=`hostname -f`
# MY_IP=`_getIpFrontend`
typeset cfg_debug=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
......@@ -58,6 +55,17 @@ IDC_svcathost__cachefile="${dir_data}/services_on_host__at-director.txt"
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(){
if [ ! -z "${dir_data}" -a -d "${dir_data}" ]; then
......@@ -72,18 +80,17 @@ IDC_svcathost__cachefile="${dir_data}/services_on_host__at-director.txt"
# ............................................................
# set $ch to store all object vars
function _generateJsonForHost(){
function _generateJsonForHost(){
if [ -z "$loadfile" ]; then
# --- host infos
# local MY_OSName=`facter os -y | grep " distid:" | cut -f 2 -d ":" | cut -f 2 -d " " | tr '[:upper:]' '[:lower:]'`
# 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 ' '`
. `dirname $0`/plugins/inc_pluginfunctions
. `dirname $0`/plugins/inc_pluginfunctions || exit 1
local MY_OSName=`ph.getOS`
local MY_OSMajorVersion=`ph.getOSMajor`
fi
export CFGSTORAGE="directorhost"
(
......@@ -112,7 +119,10 @@ IDC_svcathost__cachefile="${dir_data}/services_on_host__at-director.txt"
# ----- set host type
# 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
if [ $? -eq 0 ]; then
$ch --set imports '["host passive only"]'
else
$ch --set imports '["host in network"]'
# port checks initiated by icinga server to monitor client
......@@ -120,10 +130,7 @@ IDC_svcathost__cachefile="${dir_data}/services_on_host__at-director.txt"
host_vars_tcpport=`echo ${host_vars_tcpport} | sed "s# ##g"`
$ch --set vars.tcp_port ${host_vars_tcpport}
fi
)
# ONE private network
echo $MY_IP | grep "^10\." >/dev/null && $ch --set imports '["host passive only"]'
fi
# ----- /host type
......@@ -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
function _initHostdata(){
# UNUSED
function UNUSED_initHostdata(){
export CFGSTORAGE="directorhost"
(
$ch --flush
......@@ -754,6 +762,9 @@ echo
cd `dirname $0`
ls ./`basename $0` >/dev/null || exit 1
_initVars
# ensure that ./inc_getconfig.sh was loaded
if [ -z "${dir_cfg}" ]; then
echo ERROR: Client is not installed/ configured yet on this machine.
......@@ -786,6 +797,18 @@ do
'--dryrun')
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
......@@ -804,6 +827,10 @@ do
'--hd' | '--hostdelete')
hostDelete
;;
'--hs' | '--hostshow')
_generateJsonForHost
$ch --json 2>/dev/null
;;
# ----- check actions
......
......@@ -63,12 +63,21 @@
# get a list of config file of all checks to execute
# no params
function getChecks(){
if [ -d ${dir_cfg}/checks/ ]; then
for myconfig in `ls -1 ${dir_cfg}/checks/*`
if [ -z "${dir_checks}" ]; then
echo "ERROR: config dir for checks is empty."
echo "Verify value of dir_checks in $dir_cfg/client.cfg"
exit 1
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
fi
}
# parse a config file and set global vars:
......
plugins @ 1dfbc60f
Subproject commit 3434a495ba0f558aa327b79ca5eae44c5d0ca6b6
Subproject commit 1dfbc60f30f390ea65471fb383525e0ec8c5cb94
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment