Nagios如何从命令中的文件中读取属性值?

问题描述 投票:0回答:1

我编写了一个bash脚本来获取写入/usr/local/nagios/etc/resource.cfg文件的授权标记令牌。 bash脚本工作正常,在resource.cfg中,令牌值保存如下,

ACCESS_TOKEN="Authorization: Bearer 38255d19-724a-4e2c-b8bc-1234retff13"

配置nagios服务时,我需要从上面的文件中读取授权头。

define command{
    command_name    check_post_https_with_args
    command_line    /usr/local/nagios/libexec/check_http -H $HOSTADDRESS$ -S -u $ARG1$ -k /usr/local/nagios/etc/resource.cfg echo $ACCESS_TOKEN  --method=POST --post $ARG2$ -T 'application/json' 
} 

define service{
    use             generic-service 
    host_name           www.cardgen.com
    service_description     post request checker
    is_volatile         0
    check_period            24x7
    check_interval                  1
    max_check_attempts      3
    normal_check_interval       1
    retry_check_interval        1
    contact_groups          admin_group
    notification_interval       120
    notification_period     24x7
    notification_options        w,u,c,r
    check_command check_post_https_with_args!/api/load/validatereadDetails=true!'{\"referenceId:145\",\"amount:500\"}'
}

这似乎不起作用,任何人都可以指导我如何通过读取文件访问命令中的标头值?

shell nagios
1个回答
0
投票

因为check_http插件不支持直接从文件加载标题,所以您应该使用resource.cfg作为敏感数据的存储,例如用户名或宏$USERx$中的密码。

所以,你的resource.cfg文件应该包含这样的东西:

$USER3$=Bearer
$USER4$=38255d19-724a-4e2c-b8bc-1234retff13

这应该是你的命令定义:

define command{
    command_name    check_post_https_with_args
    command_line    /usr/local/nagios/libexec/check_http -H $HOSTADDRESS$ -S -u $ARG1$ -k "Authorization: $USER3$ $USER4$"  --method=POST --post $ARG2$ -T 'application/json' 
}

PS:您不能将所有这些存储在一个宏中,因为Nagios宏不能包含空格字符。

© www.soinside.com 2019 - 2024. All rights reserved.