Local variable in nagios config

Is it possible to have local variables in Nagios config files?

I'm probably doing something a little "wrong", but I think this will fit my specific usecase the best.

I have lots of VERY different services I need to monitor. They might change independently of each other or they might stay the same. I know I can use host groups and add my services to monitor a given hostgroup, and then add hosts to that group and remove them as needed.

But honestly I just wanted to define those 5-6 services I need to monitor, right beside my host definition in the servers folder. This works great, but I have this cumbersome job everytime I copy the file to monitor a new host, that I need to input the IP and redefine the hostname all the way down (beside making tweaks where needed).

Can't I somehow define the hostname at the top of the config file and have it cascade to all the service definition in the same config file? That would really help me out.

0
задан 2 December 2016 в 17:58
1 ответ

Вы можете создать шаблон, а затем заставить хосты использовать этот шаблон. Пример из документации nagios:

define host{
    host_name       bighost1
    check_command       check-host-alive
    notification_options    d,u,r
    max_check_attempts  5
    name            hosttemplate1
    }
define host{
    host_name       bighost2
    max_check_attempts  3
    use         hosttemplate1
    }

Когда вы запрашиваете переменные для каждого файла. Это не сработает. В Nagios нет концепции отдельных файлов конфигурации. Просто забирает все предметы. Итак, если вы определяете макрос вроде $ MYIPMACRO: 192.168.0.1 $ , этот макрос верен для ВСЕХ объектов, всей вашей конфигурации nagios. Я думаю, что icinga2 может делать то, что вы хотите, и совместим с плагинами nagios check.

0
ответ дан 24 November 2019 в 05:20

Теги

Похожие вопросы