具有多行输出的 Icinga2 插件

具有多行输出的 Icinga2 插件

我正在尝试为 Icinga2 编写一个自定义插件,该插件可从我们向客户提供的产品中获取许可证信息。这是一个非常简单的脚本,但有多行输出,我正在尝试收集数据并在特定主机的服务下对其进行格式化。

以下是数据的输出:

Users of product1, Total issued=10, Total used=0
Users of product2, Total issued=10, Total used=0
Users of product3, Total issued=10, Total used=0
Users of product4, Total issued=10, Total used=0
Users of product5, Total issued=50, Total used=11
Users of product6, Total issued=10, Total used=0
Users of product7, Total issued=771, Total used=0
Users of product8, Total issued=771, Total used=8
Users of product9, Total issued=771, Total used=0
Users of product10, Total issued=60, Total used=0

以下是我认为需要传递给 Icinga2 的内容:

COMSOL CHECK OK : Users of=product1, Total issued=10, Total used=0| UsersOf=product1;;;; TotalIssued=10;;;; TotalUsed=0;;;;
COMSOL CHECK OK : Users of=product2, Total issued=10, Total used=0| UsersOf=product2;;;; TotalIssued=10;;;; TotalUsed=0;;;;
COMSOL CHECK OK : Users of=product3, Total issued=10, Total used=0| UsersOf=product3;;;; TotalIssued=10;;;; TotalUsed=0;;;;
COMSOL CHECK OK : Users of=product4, Total issued=10, Total used=0| UsersOf=product4;;;; TotalIssued=10;;;; TotalUsed=0;;;;
COMSOL CHECK OK : Users of=product5, Total issued=50, Total used=11| UsersOf=product5;;;; TotalIssued=50;;;; TotalUsed=11;;;;
COMSOL CHECK OK : Users of=product6, Total issued=10, Total used=0| UsersOf=product6;;;; TotalIssued=10;;;; TotalUsed=0;;;;
COMSOL CHECK OK : Users of=product7, Total issued=771, Total used=0| UsersOf=product7;;;; TotalIssued=771;;;; TotalUsed=0;;;;
COMSOL CHECK OK : Users of=product8, Total issued=771, Total used=8| UsersOf=product8;;;; TotalIssued=771;;;; TotalUsed=8;;;;
COMSOL CHECK OK : Users of=product9, Total issued=771, Total used=0| UsersOf=product9;;;; TotalIssued=771;;;; TotalUsed=0;;;;
COMSOL CHECK OK : Users of=product10, Total issued=60, Total used=0| UsersOf=product10;;;; TotalIssued=60;;;; TotalUsed=0;;;;

这是我的脚本:

#!/bin/bash
license=$(/opt/licenses/comsol/lmstat -a |grep 'Users of' |sed 's/://g' |head -10| awk '{print "COMSOL CHECK OK : Users of="$3", Total issued="$6", Total used="$11 "| UsersOf="$3";;;; TotalIssued="$6";;;; TotalUsed="$11";;;;" }') 

printf "${license}\n"

正如您所看到的,它非常简单,但是我在 Icinga 的这个配置中收到以下错误......

Plugin Output
sed: couldn't write 85 items to stdout: Broken pipe
grep: write error: Broken pipe
COMSOL CHECK OK : Users of=product1, Total issued=10, Total used=0
COMSOL CHECK OK : Users of=product2, Total issued=10, Total used=0
COMSOL CHECK OK : Users of=product3, Total issued=10, Total used=0
COMSOL CHECK OK : Users of=product4, Total issued=10, Total used=0
COMSOL CHECK OK : Users of=product5, Total issued=50, Total used=10
COMSOL CHECK OK : Users of=product6, Total issued=10, Total used=0
COMSOL CHECK OK : Users of=product7, Total issued=771, Total used=0
COMSOL CHECK OK : Users of=product8, Total issued=771, Total used=8
COMSOL CHECK OK : Users of=product9, Total issued=771, Total used=0
COMSOL CHECK OK : Users of=product10, Total issued=60, Total used=0

我甚至尝试将其全部传递到一行,因此输出如下:

COMSOL CHECK OK : Users of=product1, Total issued=10, Total used=0| UsersOf=product1;;;; TotalIssued=10;;;; TotalUsed=0;;;; Users of=product2, Total   issued=10, Total used=0| UsersOf=product2;;;; TotalIssued=10;;;; TotalUsed=0;;;; Users of=product3, Total issued=10, Total used=0| UsersOf=product3;;;; TotalIssued=10;;;; TotalUsed=0;;;; Users of=product4, Total issued=10, Total used=0| UsersOf=product4;;;; TotalIssued=10;;;; TotalUsed=0;;;; Users of=product5, Total issued=50, Total used=10| UsersOf=product5;;;; TotalIssued=50;;;; TotalUsed=10;;;; Users of=product6, Total issued=10, Total used=0| UsersOf=product6;;;; TotalIssued=10;;;; TotalUsed=0;;;; Users of=product7, Total issued=771, Total used=0| UsersOf=product7;;;; TotalIssued=771;;;; TotalUsed=0;;;; Users of=product8, Total issued=771, Total used=8| UsersOf=product8;;;; TotalIssued=771;;;; TotalUsed=8;;;; Users of=product9, Total issued=771, Total used=0| UsersOf=product9;;;; TotalIssued=771;;;; TotalUsed=0;;;; Users of=product10, Total issued=60, Total used=0| UsersOf=product10;;;; TotalIssued=60;;;; TotalUsed=0;;;;

有什么想法可以让它工作吗...它会工作吗?

谢谢!乔

答案1

性能数据值必须是整数。请参阅https://www.monitoring-plugins.org/doc/guidelines.html#AEN201

相关内容