1 != 1 … it’s a type thing

I found myself scripting a nagios check the other day. That in itself isn’t unusual, but in this case I was writing a script to run via NRPE on a windows host using WSH/VB. The script was intended to received 3 parameters: a string, a warning number and a critical number. It would then list all the processes on the windows host and see if they matched the string. If so it would count them and compare that count to the critical and warning values.

As I was testing the warning and critical values seemed to not behave as expected. So I added some good old fashioned debug printing and to my surprise found that according the output the number of processes (1) was not equal to the passed value (1). In essence, I was being told that 1 was not equal to 1.

Unlike Perl, it seems that WSH is not as gifted at automatic type conversions and in one case the 1 was an integer (the one I counted), while the other was a string (the one I passed on the command line).

I did some digging and found quite a few links that suggested that type conversion is possible, but I did not come across an example of how to actually do it. A friend of mine suggested I force it by computation, which would not alter the value. So I did the following:

warningValue = warningValue + 0

That worked like a charm.

Leave a Reply

Your email address will not be published. Required fields are marked *