I noticed an issue with the way you calculate the time difference:
my $deltacsn = abs( $mastercsn_elts[0] - $slavecsn_elts[0] );
and then print:
"WARNING - directories are not in sync with $master_host - $deltacsn seconds late (W:$warning - C:$critical)$perfparse";
However the delta between two ContextCSN timestamps in decimal notation cannot simply be interpreted as seconds...
For example, take 2016/09/21 13:02:23 and 2016/09/21 12:07:24.
You calculate: 20160921130223 - 20160921120724 and print: "9499 seconds late", while it is fact only 54:59 or 3299 seconds.
You need to substract seconds/minutes/hours(days?) individually and then glue them back together.
It's not just a display problem. Eg. an alert threshold of 300 seconds (5 minutes) is reached already after 3:00 (3 minutes).
Found by Geert Hendrickx: