From 5c82d7fa025380ce26d2be4bf1452f1f3d23c5d9 Mon Sep 17 00:00:00 2001 From: Recolic Keghart <root@recolic.net> Date: Thu, 12 May 2022 13:59:58 +0800 Subject: [PATCH] detect planError state in jobstatus monitor --- antidote-cis | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/antidote-cis b/antidote-cis index 3143919..1274481 100755 --- a/antidote-cis +++ b/antidote-cis @@ -196,10 +196,21 @@ function cis_run_job () { function cis_get_job_status () { # Argument should be job_id of *root* workflow. (not child workflow!) - # Returns job summary in stdout. + # Returns job status in stdout, maybe InProgress, NotStarted, Failed, Blocked, Finished, or some other unknown status. + # Returns job summary in stderr, in plain text or markdown format. jobid="$1" getjobhierarchy_apires=`curl_wrapped "https://beta-cps.trafficmanager.net/cis.client.svc/Public/$cis_namespace/GenericJob/$jobid/GetJobHierarchy"` && subworkflows_text=`echo "$getjobhierarchy_apires" | json2table DisplayName,Id,DisplayStatus,JobType -p` || ! echo2 "API GetJobHierarchy failed" || return $? + callstack_formatted=`echo "$getjobhierarchy_apires" | json2table DisplayName,Id,DisplayStatus | grep -E '( InProgress )|( PlanError )'` || ! echo2 "API GetJobHierarchy failed" || return $? + _mdcode='```' + + if planerror_callstack=`echo "$subworkflows_text" | grep -F '|PlanError|'`; then + # RemoteJob may have PlanError in subworkflow. The top-level workflow is still InProgress but bottom workflow got PlanError. + [[ ! -v ANTIDOTE_JOBSTAT_MARKDOWN ]] && + echo2 -e ">>> CIS reported PlanError:\nCallstack: \n$callstack_formatted\nCIS Log: https://beta-cps.trafficmanager.net/Public/$cis_namespace/JobDetails/$jobid" || + echo2 -e "## CIS reported PlanError\n\n[View CIS Log](https://beta-cps.trafficmanager.net/Public/$cis_namespace/JobDetails/$jobid)\n\n### Callstack\n\n$_mdcode\n$callstack_formatted\n$_mdcode\n" + echo "Failed" && return 0 + fi if inprogress_callstack=`echo "$subworkflows_text" | grep -F '|InProgress|'`; then # There's some workflow in-progress. It maybe inprogress or blocked. # Note that, there may be multiple workflows in "InProgress" state. In this scenario, @@ -213,9 +224,7 @@ function cis_get_job_status () { bottom_wf_activities=`echo "$bottom_wf_pagedtasks_apires" | json2table Data/Tasks/DisplayName,StateName` || ! echo2 "API WithPagedTasksAndIncidents failed" || return $? if echo "$bottom_wf_activities" | tr -d ' ' | grep -F '|Blocked|' > /dev/null; then # I found some activity blocked! Show incident and exit. - callstack_formatted=`echo "$getjobhierarchy_apires" | json2table DisplayName,Id,DisplayStatus | grep -F ' InProgress '` || ! echo2 "API GetJobHierarchy failed" || return $? icm_link=`echo "$bottom_wf_pagedtasks_apires" | json2table Data/Tasks/Incidents/ExternalLink -p | sed 's/VAL: //g' | tr -d '|'` || icm_link="" - _mdcode='```' [[ ! -v ANTIDOTE_JOBSTAT_MARKDOWN ]] && echo2 -e ">>> Incident detected:\nCallstack: \n$callstack_formatted\nActivity: \n$bottom_wf_activities\nCIS Log: https://beta-cps.trafficmanager.net/Public/$cis_namespace/JobDetails/$jobid\nICM Link: $icm_link" || echo2 -e "## Incident detected\n\n[View CIS Log](https://beta-cps.trafficmanager.net/Public/$cis_namespace/JobDetails/$jobid)\n\n### Callstack\n\n$_mdcode\n$callstack_formatted\n$_mdcode\n\n### Activity\n\n$_mdcode\n$bottom_wf_activities\n$_mdcode\n[View ICM Incident]($icm_link)" @@ -297,7 +306,7 @@ function subcmd_listver () { } # Initialization -antidote_version="1.1.04" +antidote_version="1.1.05" subcmd="$1" shift -- GitLab