i need to get one item out of an array as string. In this example the array only has one entry.
What I want to do, is to restart a service when it crashed with an event command.
The dummy (not working ) version inside the event command:
var restart_service = ($service.vars.IcingaCheckService_Array_Service$).ConvertFirstValueFoundInArrayToString
$ icinga2 console
Icinga 2 (version: v2.11.0-330-g1a503b554)
Type $help to view available commands.
<1> => var arr = [ 1, 2, 3 ]
null
<2> => var res; if (len(arr) > 0) { res = arr[0].to_string() }; res
"1"
All types provide a to_string method. If you’re not certain about this, you could always use typeof() for additional sanity checks.
var res; if (len(arr) > 0) { var r = arr[0]; if (typeof(r) == Number) { res = r.to_string() } }; res