Slair1 commented on a change in pull request #3908: Alert on certain host 
status transitions
URL: https://github.com/apache/cloudstack/pull/3908#discussion_r382885204
 
 

 ##########
 File path: 
engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java
 ##########
 @@ -1432,14 +1436,29 @@ public boolean agentStatusTransitTo(final HostVO host, 
final Status.Event e, fin
 
             host.setManagementServerId(msId);
             try {
-                return _statusStateMachine.transitTo(host, e, host.getId(), 
_hostDao);
+                final Status hostStatus = host.getStatus();
+                final Status nextStatus = hostStatus.getNextStatus(e);
+
+                didTransit = _statusStateMachine.transitTo(host, e, 
host.getId(), _hostDao);
+                if (status_logger.isDebugEnabled()) {
+                    status_logger.debug("agentStatusTransitTo: old status - " 
+ hostStatus + ", event - " + e + ", new status - " + nextStatus + " (" + 
(didTransit ? "success)" : "failed)"));
+                }
+                if (AlertOnHostTransitions.value() && 
hostStatus.getTransitionAlertFlag(e)) {
+                    final DateTimeFormatter dateFormatter = 
DateTimeFormatter.ofPattern("yyyy-MM-dd H:m:s,SSS");
+                    final String hostShortDesc = host.getName() + " (id:" + 
host.getId() + ")";
+                    
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, 
host.getDataCenterId(), host.getPodId(), host.getName() + " transit from " + 
hostStatus + " to " + nextStatus +  " (" + (didTransit ? "success)" : 
"failed)"),
+                        (dateFormatter.format(LocalDateTime.now())) + 
"\r\nTransit agent status with event " + e + " for host " + hostShortDesc + " 
from " + hostStatus + " to " + nextStatus + (didTransit ? " was successful" : " 
failed"));
+                }
+
 
 Review comment:
   Above code is what raises the alert if both the ConfigKey is set and the 
TransitionAlertFlag is set for the particular Transition

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to