give HostStatus analyzer more info: details on ping success/failure and ping duration
[pingcheck] / src / icmp / icmppinger.cpp
index 93a071d..12832d6 100644 (file)
@@ -127,7 +127,7 @@ IcmpPinger::~IcmpPinger()
 void IcmpPinger::ping(
         const address &destination_ip,
         const uint16_t /*destination_port*/, // the ICMP protocol does not use ports
-        function<void(bool)> ping_done_callback
+        function<void(PingStatus)> ping_done_callback
 )
 {
     PingDoneCallback = ping_done_callback;
@@ -238,7 +238,7 @@ void IcmpPinger::schedule_timeout_echo_reply()
 /**
  * @brief Gets called when the ping is finished: Either on timeout or on ping reply
  *
- * @return void
+ * @return void (but calls PingDoneCallback)
  **/
 void IcmpPinger::handle_timeout(const boost::system::error_code& error)
 {
@@ -247,32 +247,34 @@ void IcmpPinger::handle_timeout(const boost::system::error_code& error)
         if ( error ==  boost::asio::error::operation_aborted )
         {
             if (! ReplyReceived)
+            {
                 GlobalLogger.notice() << LogPrefix
                     << "Timer waiting for ICMP echo reply was cancelled!"
                     << endl;
+                set_ping_status( PingStatus_FailureAsyncCancel );
+            }
             // otherwise probably called by IcmpPacketReceiveTimer.cancel in
             // handle_receive_icmp_packet!
         }
         else
+        {
             GlobalLogger.notice() << LogPrefix << "Error " << error
                 << " waiting for ICMP echo reply!" << endl;
+            set_ping_status( PingStatus_FailureAsyncError );
+        }
 
         // Still continue with rest of function, so PingStatus is updated and Callback executed
         //   when timer was cancelled
     }
-
-    // Check ReplyReceived as the timer handler
-    // is also called by Timer.cancel();
-    if ( !ReplyReceived )
-    {
+    else if ( !ReplyReceived )
+    {    // Check ReplyReceived since the timer handler is also called by Timer.cancel();
         GlobalLogger.info() << LogPrefix << "Request timed out" << endl;
 
         set_ping_status( PingStatus_FailureTimeout );
     }
 
     // Call ping-done handler
-    bool ping_success = (PingerStatus == PingStatus_SuccessReply);
-    PingDoneCallback( ping_success );
+    PingDoneCallback( PingerStatus );
 }