Datasource Programs + macros

This forum was archived to /woltlab and is now in read-only mode.
  • hi all,
    I have a following scenario: Datasource Programs->Individual program call instead of agent access,


    We know that $HOSTNAME$: is the name of the host

    e.g. Hostname: ABC

    cat /home/cmk/Dep/${$HOSTNAME$:0:1}/$HOSTNAME$/check_mk_agent.txt


    ${$HOSTNAME$:0:1} <-- This part is not working, but when I print on terminal echo ${HOSTNAME:0:1} it works, does this work only for ENV ?

    This is my goal: cat /home/cmk/Dep/A/ABC/check_mk_agent.txt

    Can I see any where in log files how check_mk translate the command ?


    In less /omd/sites/mysite/var/log/web.log:

    MKGeneralException: Agent exited with code 2: /bin/sh: 1: Bad substitution


    In less /omd/sites/mysite/var/nagios/nagios.log:

    [1513155651] INITIAL SERVICE STATE: ABC;Check_MK;CRITICAL;HARD;1;CRIT - Agent exited with code 2: /bin/sh: 1: Bad substitution



    Thank you for any help you can provide

    Neeloj

  • With # ps aux | grep check_mk_agent.txt you can see the full command line when cmk calls the datasource program. You can force the call by running a # cmk -d HOST and then check with the ps command immediately afterwards.


    I guess the hostname does not get translated within the substitution.

  • thanks for your answer TheLucKy


    I changed my command to :

    host_name=$HOSTNAME$ ; cat /home/cmk/Dep/"${host_name_vis:0:1}"/$HOSTNAME$/check_mk_agent.txt


    And in the var/check_mk/precompiled/ABC.py is translated into:


    def get_datasource_program(hostname, ipaddress):

    return {'ABC': 'host_name=ABC; cat /home/cmk/Dep/"${host_name:0:1}"/ABC/check_mk_agent.txt'}[hostname]



    and when I copy :
    host_name=ABC; cat /home/cmk/Dep/"${host_name:0:1}"/ABC/check_mk_agent.txt


    and paste into Terminal it print for meme the content of the check_mk_agent.txt


    I still get: Service discovery failed for this host: Agent exited with code 2: /bin/sh: 1: Bad substitution


    I guess the hostname does not get translated within the substitution.

    I think the same hmm...

  • You really have to check the command line call with ps to know whats up.


    BUT, what you can do is to write a small shell script that accepts the $HOSTNAME$ variable as argument and use that as datasource program. So you can do the directory selection within the script easily. That is the better and "cleaner" way to use the datasource program functionality anyway to be honest.

  • BUT, what you can do is to write a small shell script that accepts the $HOSTNAME$ variable as argument and use that as datasource program. So you can do the directory selection within the script easily. That is the better and "cleaner" way to use the datasource program functionality anyway to be honest.

    thank you so much, this was much easier :-), and already solved :-)