Format Exit Code

I grabbed some relevance that was posted on the forum a few years back and dropped it into a table. I would like to display the exit code in a useful way. For every exit code that starts with “-” i would want to take that exit code and convert it using relevance. For example (-2146498497 as integer) as hexadecimal and display the converted exit code in the report. Would anyone be able to help me out with this?

(html "<table id=resultsTable class=sortable>" & html ("<th>Computer Name</th><th>Baseline</th><th>Fixlet</th><th>Status</th><th>Exit Code</th><th>Retries</th><th>End Time</th>") & 
(it) & html "</table>"

) of concatenations of trs of (

td of (item 0 of it) &
td of (item 1 of it) &
td of (item 2 of it) &
td of (item 3 of it) &
td of (item 4 of it) &
td of (item 5 of it) &
td of (item 6 of it)

) of (

name of computer of it, 
name of parent group of action of it, 
name of action of it, 
detailed status of it, 
exit code of it as string | "n/a",
retry count of it as string, 
end time of it as string | "n/a"

) of (results whose
 
(status of it as string != "Not Relevant") of member actions of bes actions whose (top level flag of it AND name of it as lowercase contains "patch-april" and state of it is contained by "Open|Expired|Stopped"))

This may help

2 Likes

Thanks for the reply. Yes, I am familiar with converting the exit code using relevance. My issue is the folks i’m preparing these reports for will not have familiarity with relevance. I was hoping i could handle this conversion in the report itself. It would be too tedious for me to have to manually search/replace all these exit codes prior to sending out the report each time because of the scale of systems i’m patching.

Yes, so in the session Relevance query try changing

exit code of it as string | "n/a",

To

((exit code of it as integer) as hexadecimal as string) | "n/a",

Thanks @JasonWalker but wouldn’t we only want to do that conversion if the exit code starts with a “-”

A common exit code is 112 (disk space issue i believe). This would get converted to 70. I’m going to embarrass myself with my lack of relevance knowledge… wouldn’t i have to do something like this

if (exit code of it) whose (it starts with "-") then ((exit code of it as integer) as hexadecimal as string) | "n/a" else exit code of it as string | "n/a",

Ok, but even with hexadecimal exit codes, they don’t always end up represented as negative signed integers.
It may be easier to just have two columns in the report? One for ‘Exit code (integer)’ and another for ‘Exit code (hexadecimal)’

In that case, yes (i wasn’t aware they weren’t always represented as negative integers). I will just break them out into 2 different columns. One last follow up question. In order to remove the leading “fffff” in the converted exit codes… can that could be accomplished using regex?

I would probably front-pad with ‘0’ and then take the last 8 characters. A little formatting I think should work (on my phone again, can’t test it)

(("0x" & last 8 of ("0000000" & (exit code of it as integer) as hexadecimal as string))) | "n/a",

Yes, I was just able to test, and aside from an unnecessary set of parentheses, this works as expected:

(("0x" & last 8 of ("0000000" & (exit code of it as integer) as hexadecimal as string)) | "n/a") of results of bes actions

yes, works as advertised. Thanks a lot Jason! As always, i appreciate your help.

1 Like