diff --git a/_etc/client.cfg.dist b/_etc/client.cfg.dist index be45f31d3d1f23ba317afb3a3a05f05c57abefd3..b2fb076ca365dc05654a1616cb6745994161d72e 100644 --- a/_etc/client.cfg.dist +++ b/_etc/client.cfg.dist @@ -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}" diff --git a/director-cli.sh b/director-cli.sh index 4694559a43e9192c905bffe662ede6709c206745..584b6f3060ef3e1abfbd00054934a5e7beacfa84 100755 --- a/director-cli.sh +++ b/director-cli.sh @@ -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(){ - # --- 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 "'"` + if [ -z "$loadfile" ]; then + # --- host infos - # local MY_Platform=`facter kernel | tr '[:upper:]' '[:lower:]'` - local MY_Platform=`uname -a | cut -f 1 -d ' '` - . `dirname $0`/plugins/inc_pluginfunctions - local MY_OSName=`ph.getOS` - local MY_OSMajorVersion=`ph.getOSMajor` + local MY_Platform=`uname -a | cut -f 1 -d ' '` + . `dirname $0`/plugins/inc_pluginfunctions || exit 1 + local MY_OSName=`ph.getOS` + local MY_OSMajorVersion=`ph.getOSMajor` + fi export CFGSTORAGE="directorhost" ( @@ -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_alt \"${MY_Platform}\:\ ${MY_OSName}\ ${MY_OSMajorVersion}\" - ) 2>/dev/null + ) 2>/dev/null # --- detect phase # local phase="live" @@ -111,19 +118,19 @@ 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 && ( - $ch --set imports '["host in network"]' - - # port checks initiated by icinga server to monitor client - 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 - ) + # host in the UNIBE network: + 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"]' - # ONE private network - echo $MY_IP | grep "^10\." >/dev/null && $ch --set imports '["host passive only"]' + # port checks initiated by icinga server to monitor client + 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 @@ -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 diff --git a/inc_functions.sh b/inc_functions.sh index da9aab2d08514d0c165d60d6e7e67b53c329d785..c1affcc9f1c28d06e14cab049f3a348cd279c410 100644 --- a/inc_functions.sh +++ b/inc_functions.sh @@ -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/*` - do - echo ${myconfig} - done + 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 } # parse a config file and set global vars: diff --git a/plugins b/plugins index 3434a495ba0f558aa327b79ca5eae44c5d0ca6b6..1dfbc60f30f390ea65471fb383525e0ec8c5cb94 160000 --- a/plugins +++ b/plugins @@ -1 +1 @@ -Subproject commit 3434a495ba0f558aa327b79ca5eae44c5d0ca6b6 +Subproject commit 1dfbc60f30f390ea65471fb383525e0ec8c5cb94