【发布时间】:2021-05-15 02:04:29
【问题描述】:
我将 JSON 提供给一些 webhook 以触发通知 (M$ Teams)。这很好用。但是,我想扩展我的 Perl 脚本:我需要在特定条件下将一个新节点添加到我的“消息卡”构造中。
例如我定义了这个:
my $payload={};
$payload = {
'@type' => 'MessageCard',
'@context' => 'http://schema.org/extensions',
themeColor => $event{COLOR},
text => $event{SERVICEOUTPUT},
sections => [{
facts => [{
name => 'Type',
value => "$event{NOTIFICATIONTYPE} $event{ADDITIONALINFO}"
},
]
}],
potentialAction => [{
'@type' => "OpenUri",
name => "View Monitoring",
targets => [{
os => "default",
uri => $naemon_url
}]
}]
};
$ua = LWP::UserAgent->new;
my $req = POST($opt_webhook
, 'Content-Type' => 'application/json; charset=UTF-8'
, 'Content' => encode_json($payload)
);
my $resp = $ua->request($req);
如果(条件),我想将其扩展如下(顺序很重要):
$payload = {
'@type' => 'MessageCard',
'@context' => 'http://schema.org/extensions',
themeColor => $event{COLOR},
text => $event{SERVICEOUTPUT},
sections => [{
facts => [{
name => 'Type',
value => "$event{NOTIFICATIONTYPE} $event{ADDITIONALINFO}"
},
]
}],
potentialAction => [{
'@type' => "OpenUri",
name => "View Monitoring",
targets => [{
os => "default",
uri => $naemon_url
}]
},
{
'@type' => "OpenUri",
name => "Notes (Logs, Docs,..)",
targets => [{
os => "default",
uri => $event{SERVICENOTESURL}
}]
}]
};
我不确定如何实现这一点。谁能提供智慧如何解决这个问题?
【问题讨论】:
-
您是否开启了
use strict和use warnings?您的$ua未声明。 -
@simbabque 是的,这只是当前代码的摘录