Hi Antony,
You can try this:
1. vi /etc/icinga2/functions.conf
2. Paste
globals.get_display_name = function(h) {
d = get_host(h).display_name
if (d) {
log(LogInformation, "get_display_name", "Display name found!")
return d
}
log(LogWarning, "get_display_name", "Display name not found!")
return "None"
}
3. vi /etc/icinga2/icinga2.conf
4. Add include "functions.conf" under include "constants.conf"
/**
* The constants.conf defines global constants.
*/
include "constants.conf"
include "functions.conf"
5. service icinga2 reload
6. use can now use get_display_name("hostname")
Kind Regards,
Ivo Kidze
Sr. IT Analyst - Monitoring Team Lead
Duke University OIT
334 Blackwell St, Suite 2109
Durham, NC 27701
Mobile: (919) 987-6364
[email protected]
I am committed to providing you with the highest quality service. Keep in touch.
-----Original Message-----
From: icinga-users [mailto:[email protected]] On Behalf Of
Antony Stone
Sent: Monday, March 18, 2019 11:31 AM
To: Icinga User's Corner <[email protected]>
Subject: Re: [icinga-users] Get attributes of a host by reference?
On Monday 18 March 2019 at 16:09:27, Václav Mach wrote:
> Hi,
>
> have you tried debugging this using the icinga2 console?
Yes.
> If I'm correct the documentation suggests something like:
>
> ICINGA2_API_USERNAME=your_user ICINGA2_API_PASSWORD=your_pass icinga2
> console --connect
> 'https://urldefense.proofpoint.com/v2/url?u=https-3A__icingaweb2-40localhost-3A5665_&d=DwIFbA&c=imBPVzF25OnBgGmVOlcsiEgHoG1i6YHLR0Sj_gZ4adc&r=dLhm7TMuuUAhZaaelXPoEPyMbTqxkar-G5Ayny5-yLE&m=5OuMETuzhUdDcMUfQweHVCEllAdzX4AqRSzGCKbbJVU&s=yiSUjVU5KsgtOGgbnJ8UyFJpU0b6x6CkxcnvQmYRDmA&e='
Right. You can also do
icinga2 console --connect
'https://urldefense.proofpoint.com/v2/url?u=https-3A__your-5Fuser-3Ayour-5Fpass-40localhost-3A5665_&d=DwIFbA&c=imBPVzF25OnBgGmVOlcsiEgHoG1i6YHLR0Sj_gZ4adc&r=dLhm7TMuuUAhZaaelXPoEPyMbTqxkar-G5Ayny5-yLE&m=5OuMETuzhUdDcMUfQweHVCEllAdzX4AqRSzGCKbbJVU&s=2RUDJpS2NBOOAxKGNDdBIkuCXGHuviJ2xHaVgfu0ViI&e='
so long as you don't mind the password being visible in a process listing to
other users on the machine.
> After connecting you can interact with your running configuration. I
> think this can help you a lot while using the icinga2 library reference.
Agreed (in principle, anyway).
> You can try to start by running 'get_host("your_host")' and then
> continue with more complex stuff based on properties you get.
Yes, I can do everything I want to there:
<1> => a=get_host("first.server.com").vars.neighbour
null
<2> => a
"second.server.com"
<3> => b=get_host(get_host("first.server.com").vars.neighbour).display_name
null
<4> => b
"HA Pair: Berlin"
And, "HA Pair: Berlin" is indeed the display_name for "second.server.com",
which you can see is the value in vars.neighbour for "first.server.com"
So, I can get what I want in the console; it just doesn't work inside the code.
> Hope this helps, cheers.
Nice idea, but I'm still stuck about how to implement these commands where
Ineed them to work :(
Antony.
--
Schrödinger's rule of data integrity: the condition of any backup is unknown
until a restore is attempted.
Please reply to the list;
please *don't* CC me.
_______________________________________________
icinga-users mailing list
[email protected]<mailto:[email protected]>
https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.icinga.org_mailman_listinfo_icinga-2Dusers&d=DwIFbA&c=imBPVzF25OnBgGmVOlcsiEgHoG1i6YHLR0Sj_gZ4adc&r=dLhm7TMuuUAhZaaelXPoEPyMbTqxkar-G5Ayny5-yLE&m=5OuMETuzhUdDcMUfQweHVCEllAdzX4AqRSzGCKbbJVU&s=zoClzI7Ytr29q6RjULu3-GEhtxxCbs2X4goqRFS0Ck8&e=
_______________________________________________
icinga-users mailing list
[email protected]
https://lists.icinga.org/mailman/listinfo/icinga-users