data validation and exception logging in IKL

data validation and exception logging in IKL
0


I was doing a code review and came across this code:

#    Internet address:     192.168.192.10 netmask 255.255.255.0
/^\s+Internet address:\s+[0-9]+\./{
writeComplexMetricStringWithLiveConfig("network-interface-ipv4-address", tags, $3, "Network Interfaces - IPv4 Address")

if ($NF in netMaskToCIDR){
    writeComplexMetricString("network-interface-ipv4-subnet", tags, netMaskToCIDR[$NF])
}

}

The question that came up for me is: what should we do if the check, if ($NF in netMaskToCIDR), fails? In the above code, we’re just “swallowing” the “error” – if the check fails, it fails silently.


We figured out a good solution for this specific code (if the check fails, report a “bad netmask” back to the user), but I’ve seen other things like this that make me wonder about adding some kind of logging facility to IKL, so that we can make validation checks on data and then let Indeni know (via logging) if those checks fail. Otherwise, it’s easy to see how scripts could be either a) just written incorrectly and never writing metrics or b) getting bad input and failing and we would never ever know about it.


I’m imagining something like I would normally use for exception logging:


if (thisInputGood(input))

# great! write my awesome code

else

log (“error”, "bad input: " + input)

We will add this to our backlog. I will follow up with implementation details once we start working on this.Thanks