VCL-1082 - This closes #8 - managementnode lastcheckin conversion to db epoch
diff --git a/managementnode/bin/monitor_vcld.pl b/managementnode/bin/monitor_vcld.pl
index fa0b796..503df93 100755
--- a/managementnode/bin/monitor_vcld.pl
+++ b/managementnode/bin/monitor_vcld.pl
@@ -170,27 +170,39 @@
 }
 
 my $current_epoch_seconds = convert_to_epoch_seconds();
-my $lastcheckin_epoch_seconds = convert_to_epoch_seconds($lastcheckin_timestamp);
+my $current_timestamp = makedatestring();
+my $lastcheckin_epoch_seconds = $management_node_info->{lastcheckin_epoch};
 my $lastcheckin_seconds_ago = ($current_epoch_seconds - $lastcheckin_epoch_seconds);
 
+# This message displays the timestamp information from the management node and the database
+my $detailed_ts_message = <<"END_MESSAGE";
+	Current Time = $current_timestamp
+	Current epoch = $current_epoch_seconds
+	Last Checkin Time = $lastcheckin_timestamp
+	Last Checkin epoch = $lastcheckin_epoch_seconds
+END_MESSAGE
+
 if ($lastcheckin_seconds_ago < 0) {
-	print_warning("$management_node_name last checkin time is in the future: $lastcheckin_timestamp, exiting");
+	print_warning("$management_node_name last checkin time is in the future: $lastcheckin_timestamp($lastcheckin_epoch_seconds), exiting");
 }
 elsif ($lastcheckin_seconds_ago < $lastcheckin_warning_seconds) {
-	print_message("$management_node_name last checked in $lastcheckin_seconds_ago seconds ago at $lastcheckin_timestamp");
+	print_message("$management_node_name last checked in $lastcheckin_seconds_ago seconds ago at $lastcheckin_timestamp($lastcheckin_epoch_seconds)");
 }
 elsif ($lastcheckin_seconds_ago >= $lastcheckin_critical_seconds) {
-	my $critical_message = "critical threshold exceeded, $management_node_name last checked in $lastcheckin_seconds_ago seconds ago at $lastcheckin_timestamp";
+	my $critical_message = "critical threshold exceeded, $management_node_name last checked in $lastcheckin_seconds_ago seconds ago at $lastcheckin_timestamp($lastcheckin_epoch_seconds)";
 	# Attempt to restart the vcld service
 	if ($mn_os->restart_service($vcld_service_name)) {
 		print_critical("$critical_message, $vcld_service_name service restarted");
+		print_critical($detailed_ts_message);
 	}
 	else {
 		print_critical("$critical_message, failed to restart $vcld_service_name service");
+		print_critical($detailed_ts_message);
 	}
 }
 else {
-	print_critical("last checkin warning threshold exceeded, $management_node_name last checked in $lastcheckin_seconds_ago seconds ago at $lastcheckin_timestamp");
+	print_critical("last checkin warning threshold exceeded, $management_node_name last checked in $lastcheckin_seconds_ago seconds ago at $lastcheckin_timestamp($lastcheckin_epoch_seconds)");
+	print_critical($detailed_ts_message);
 }
 
 print_message('done');
diff --git a/managementnode/lib/VCL/utils.pm b/managementnode/lib/VCL/utils.pm
index c704fe4..456013b 100644
--- a/managementnode/lib/VCL/utils.pm
+++ b/managementnode/lib/VCL/utils.pm
@@ -4621,6 +4621,7 @@
 	my $select_statement = "
 SELECT
 managementnode.*,
+UNIX_TIMESTAMP(managementnode.lastcheckin) as lastcheckin_epoch,
 resource.id AS resource_id,
 state.name AS statename
 FROM
@@ -4960,22 +4961,46 @@
 	}
 
 	# Get current timestamp
-	my $timestamp = makedatestring();
+	my $timestamp;
 
 	# Construct the update statement
 	my $update_statement = "
       UPDATE
 		managementnode
 		SET
-		lastcheckin = \'$timestamp\'
+		lastcheckin = NOW()
 		WHERE
 		id = $management_node_id
    ";
 
+	my $get_unix_timestamp = "
+	  SELECT
+	    UNIX_TIMESTAMP() as EPOC_TIMESTAMP
+    ";
+
 	# Call the database execute subroutine
 	if (database_execute($update_statement)) {
 		# Update successful, return timestamp
-		return $timestamp;
+		my @selected_rows = database_select($get_unix_timestamp);
+
+		# Check to make sure 1 row was returned
+		if (scalar @selected_rows == 0) {
+			notify($ERRORS{'WARNING'}, 0, "zero rows were returned from database select");
+			return 0;
+		}
+		elsif (scalar @selected_rows > 1) {
+			notify($ERRORS{'WARNING'}, 0, "" . scalar @selected_rows . " rows were returned from database select");
+			return 0;
+		}
+
+		# Make sure we return undef if the column wasn't found
+		if (defined $selected_rows[0]{EPOC_TIMESTAMP}) {
+			$timestamp = $selected_rows[0]{EPOC_TIMESTAMP};
+			return $timestamp;
+		} else {
+			notify($ERRORS{'CRITICAL'}, 0, "unable to get EPOC_TIMESTAMP from database");
+			return 0;
+		}
 	}
 	else {
 		notify($ERRORS{'CRITICAL'}, 0, "unable to update database, management node id $management_node_id");