We use devmon to automatically monitor a variety of things on our network, including our uninterruptible power supplies (UPSs) that ensure our core infrastructure is able to withstand short power outages.
Our UPSs should perform a self-test routine every two weeks, and thus I wanted to have our automated monitoring report on whether or not a self-test had been performed sufficiently recently. The UPSs report the date they were last tested in the format MM/DD/YYYY (i.e. today, the 8th of June 2017, is 06/08/2017), and so I needed to parse dates of that format so I could calculate the number of days since the last self-test.
Ordinarily the advice on performing any sort of date calculation when programming is “use a date library”: date calculations are notoriously difficult to get totally right, and you’re normally better off using a library that someone has written and which has already been thoroughly tested. But that’s not an option inside devmon: one can perform basic mathematical and string manipulation operations, but little else.
I wrote the monitoring report about a week ago, and it had been working fine – but I noticed that it had stopped reporting today. The first step in parsing the date is to take a string like 06/08/2017 and extract characters 1 and 2, then 4 and 5, then 7 to 10 and store them as the month, day and year respectively.
An oft-used convention in programming languages is that numbers that start with a leading zero should be interpreted as octal (base 8) numbers. Thus, in octal, the decimal numbers 1 to 10 are 01, 02, 03, 04, 05, 06, 07, 010, 011, 012.
You might now see the problem: 08 is not a valid octal number, so the underlying code stopped working today! Running devmon in debug mode quickly let me find the reason for the problem:
Illegal octal digit ‘8’ at (eval 13) line 1, at end of line
and so the fix was simply to remove any leading zeroes from the month and day.
-
Recent Posts
-
Recent Comments
-
Archives
- August 2021
- April 2021
- March 2021
- July 2020
- May 2020
- March 2020
- February 2020
- January 2020
- November 2019
- June 2019
- May 2019
- April 2019
- March 2019
- July 2018
- June 2017
- October 2016
- September 2016
- August 2016
- June 2016
- April 2016
- March 2016
- February 2016
- November 2015
- October 2015
- September 2015
- August 2015
- June 2015
- April 2015
- March 2015
- January 2015
- October 2014
- September 2014
- August 2014
- July 2014
- January 2014
- September 2013
- July 2013
- May 2013
- February 2013
- January 2013
- December 2012
- November 2012
- October 2012
-
Categories
-
Meta