我在运行一个Perl脚本后有一个输出,它有几行,但我唯一需要的是gatewayName:statusCode:“失败”,ex。
编辑:例如3个网关,2个失败2个成功,我只会收到一封电子邮件。这是一批完成后的输出。我想得到任何一个单一的电子邮件后,所有的批次都做了,或者我可以生活在每批不同的电子邮件告诉哪一个失败。
"Policy installation - Site-Firewalls" failed (100%)
tasks:
- uid: "e822c095-cb8b-4f8b-be51-c50a3bdf6aad"
type: "task"
domain:
uid: "41e821a0-3720-11e3-aa6e-0800200c9fde"
name: "SMC User"
domain-type: "domain"
task-id: "97be087a-fad4-49ca-adc0-6fa0e32b4518"
task-name: "Policy installation - Site-Firewalls"
status: "failed"
progress-percentage: 100
start-time:
posix: 1689859245449
iso-8601: "2023-07-20T09:20-0400"
last-update-time:
posix: 1689859512075
iso-8601: "2023-07-20T09:25-0400"
suppressed: false
task-details:
- uid: "aa342b56-2f4d-4354-a491-b89812b9bf65"
name: null
domain:
uid: "41e821a0-3720-11e3-aa6e-0800200c9fde"
name: "SMC User"
domain-type: "domain"
color: "black"
statusCode: "succeeded"
statusDescription: "Succeeded"
taskNotification: "e822c095-cb8b-4f8b-be51-c50a3bdf6aad"
gatewayId: "b74b22ba-cd75-4698-99b9-cc897f501fc1"
policyId: "e539bfb8-6c3c-4835-a124-53a1b616f9aa"
fastInstallStatus:
worksessionId: "3baf8bc3-52ad-42df-be15-37b5ac2aa336"
gatewayId: "b74b22ba-cd75-4698-99b9-cc897f501fc1"
policyId: "e539bfb8-6c3c-4835-a124-53a1b616f9aa"
status: "blade_not_supported"
detailedReason: []
runningStages: []
waitingStages: []
stagesInfo:
- type: "info"
stage: "legacy policy load"
messages:
- type: "info"
message: "Threat Prevention Policy installation was canceled for:"
cluster: false
meta-info:
validation-state: "ok"
last-modify-time:
posix: 1689859474791
iso-8601: "2023-07-20T09:24-0400"
last-modifier: "System"
creation-time:
posix: 1689859246735
iso-8601: "2023-07-20T09:20-0400"
creator: "System"
tags: []
icon: "General/globalsNa"
comments: ""
display-name: ""
customFields: null
gatewayName: "SF-Test1"
revision: "3baf8bc3-52ad-42df-be15-37b5ac2aa336""
- uid: "a61261c0-6f40-4a89-a2b4-ff96c097c703"
name: null
domain:
uid: "41e821a0-3720-11e3-aa6e-0800200c9fde"
name: "SMC User"
domain-type: "domain"
color: "black"
statusCode: "succeeded"
statusDescription: "Succeeded"
taskNotification: "e822c095-cb8b-4f8b-be51-c50a3bdf6aad"
gatewayId: "786eae4e-4f10-46f5-b0ef-effe426d828e"
clusterGroupId: "1e34b75a-4a79-4306-97a7-763189253649"
policyId: "e539bfb8-6c3c-4835-a124-53a1b616f9aa"
fastInstallStatus:
worksessionId: "3baf8bc3-52ad-42df-be15-37b5ac2aa336"
gatewayId: "1e34b75a-4a79-4306-97a7-763189253649"
policyId: "e539bfb8-6c3c-4835-a124-53a1b616f9aa"
status: "blade_not_supported"
detailedReason: []
runningStages: []
waitingStages: []
stagesInfo: []
cluster: false
meta-info:
validation-state: "ok"
last-modify-time:
posix: 1689859470158
iso-8601: "2023-07-20T09:24-0400"
last-modifier: "System"
creation-time:
posix: 1689859246716
iso-8601: "2023-07-20T09:20-0400"
creator: "System"
tags: []
icon: "General/globalsNa"
comments: ""
display-name: ""
customFields: null
gatewayName: "SF-Test1"
revision: "3baf8bc3-52ad-42df-be15-37b5ac2aa336"
- uid: "b2d97e39-8d7a-447f-a10b-4cc52d562197"
name: null
domain:
uid: "41e821a0-3720-11e3-aa6e-0800200c9fde"
name: "SMC User"
domain-type: "domain"
color: "black"
statusCode: "failed"
statusDescription: "Failed"
taskNotification: "e822c095-cb8b-4f8b-be51-c50a3bdf6aad"
gatewayId: "cca50637-eed9-4dbd-b64f-1f368e2882d8"
policyId: "e539bfb8-6c3c-4835-a124-53a1b616f9aa"
fastInstallStatus:
worksessionId: "3baf8bc3-52ad-42df-be15-37b5ac2aa336"
gatewayId: "cca50637-eed9-4dbd-b64f-1f368e2882d8"
policyId: "e539bfb8-6c3c-4835-a124-53a1b616f9aa"
status: "blade_not_supported"
detailedReason: []
runningStages: []
waitingStages: []
stagesInfo:
- type: "err"
stage: "legacy policy load"
messages:
- type: "err"
message: "Policy installation had failed due to an internal error. If the problem persists please contact Check Point support"
cluster: false
meta-info:
validation-state: "ok"
last-modify-time:
posix: 1689859511828
iso-8601: "2023-07-20T09:25-0400"
last-modifier: "System"
creation-time:
posix: 1689859246704
iso-8601: "2023-07-20T09:20-0400"
creator: "System"
tags: []
icon: "General/globalsNa"
comments: ""
display-name: ""
customFields: null
gatewayName: "SF-Test3"
revision: "3baf8bc3-52ad-42df-be15-37b5ac2aa336"
字符串
这是我的代码
my $results = qx/$args/; ## -----This is when the command is executed.
print $results;
###DO I NEED TO DO A FOR LOOP ?? How do I say if it fails look for the gateway?
for ($results)
{
if ($results =~ /failed/) {
#my @array = split("\n", $results);
#my $len = @array;
#my $gw1 = $array[$len-1];
#my @gw = split(/:/,$gw1);
push (@fails, $results);
}
}
## Send the report via e-mail
if (@fails){
# my ($fails) = @_;
#my $gateway=$gw[1];
my $sendmail = '/sbin/sendmail -t';
#print "this is gateway $gateway";
open (SENDMAIL, "|$sendmail") or die "Cannot open sendmail: $!";
print SENDMAIL "From:" . 'admin@test.com';
print SENDMAIL "\n";
print SENDMAIL "To:" . 'email@gmail.com';
print SENDMAIL "\n";
print SENDMAIL "Subject: " . " Failed IPS Clusters\n";
print SENDMAIL "\n";
print SENDMAIL @fails;
close (SENDMAIL);
}
}
型
3条答案
按热度按时间sirbozc51#
当在列表上下文中使用时,
qx
返回输出行的列表,而不是所有内容都在一个字符串中。然后可以像往常一样循环:字符串
好的做法是使用词法文件句柄和3-argument form of
open
:型
7ivaypg92#
下面是如何从多行字符串中提取内容的示例:
字符串
osh3o9ms3#
如果我正确理解了你的问题,那么它是,你在Perl脚本中运行命令
$args
,并将输出存储在$results
中。现在你想处理这个,并得到statusCode
和gatewayName
的值,以进一步处理。以下是您可以执行的操作:
字符串