@@ -615,107 +615,81 @@ private void generateEmailAlert(DataCenterVO dc, HostPodVO pod, ClusterVO cluste
615615
616616 String msgSubject = null ;
617617 String msgContent = null ;
618- String totalStr ;
619- String usedStr ;
620- String pctStr = formatPercent (usedCapacity / totalCapacity );
618+ String percentual = formatPercent (usedCapacity / totalCapacity );
619+ String totalInMB = formatBytesToMegabytes (totalCapacity );
620+ String usedInMB = formatBytesToMegabytes (usedCapacity );
621+ String totalInString = String .valueOf (totalCapacity );
622+ String usedInString = String .valueOf (usedCapacity );
621623 AlertType alertType = null ;
622624 Long podId = pod == null ? null : pod .getId ();
623625 Long clusterId = cluster == null ? null : cluster .getId ();
626+ String clusterName = cluster == null ? null : cluster .getName ();
627+ String podName = pod == null ? null : pod .getName ();
628+ String dataCenterName = dc .getName ();
624629
625630 switch (capacityType ) {
626-
627- //Cluster Level
628- case Capacity .CAPACITY_TYPE_MEMORY :
629- msgSubject = "System Alert: Low Available Memory in cluster " + cluster .getName () + " pod " + pod .getName () + " of availability zone " + dc .getName ();
630- totalStr = formatBytesToMegabytes (totalCapacity );
631- usedStr = formatBytesToMegabytes (usedCapacity );
632- msgContent = "System memory is low, total: " + totalStr + " MB, used: " + usedStr + " MB (" + pctStr + "%)" ;
633- alertType = AlertManager .AlertType .ALERT_TYPE_MEMORY ;
634- break ;
635- case Capacity .CAPACITY_TYPE_CPU :
636- msgSubject = "System Alert: Low Unallocated CPU in cluster " + cluster .getName () + " pod " + pod .getName () + " of availability zone " + dc .getName ();
637- totalStr = DfWhole .format (totalCapacity );
638- usedStr = DfWhole .format (usedCapacity );
639- msgContent = "Unallocated CPU is low, total: " + totalStr + " Mhz, used: " + usedStr + " Mhz (" + pctStr + "%)" ;
640- alertType = AlertManager .AlertType .ALERT_TYPE_CPU ;
641- break ;
642- case Capacity .CAPACITY_TYPE_STORAGE :
643- msgSubject = "System Alert: Low Available Storage in cluster " + cluster .getName () + " pod " + pod .getName () + " of availability zone " + dc .getName ();
644- totalStr = formatBytesToMegabytes (totalCapacity );
645- usedStr = formatBytesToMegabytes (usedCapacity );
646- msgContent = "Available storage space is low, total: " + totalStr + " MB, used: " + usedStr + " MB (" + pctStr + "%)" ;
647- alertType = AlertManager .AlertType .ALERT_TYPE_STORAGE ;
648- break ;
649- case Capacity .CAPACITY_TYPE_STORAGE_ALLOCATED :
650- msgSubject = "System Alert: Remaining unallocated Storage is low in cluster " + cluster .getName () + " pod " + pod .getName () + " of availability zone " +
651- dc .getName ();
652- totalStr = formatBytesToMegabytes (totalCapacity );
653- usedStr = formatBytesToMegabytes (usedCapacity );
654- msgContent = "Unallocated storage space is low, total: " + totalStr + " MB, allocated: " + usedStr + " MB (" + pctStr + "%)" ;
655- alertType = AlertManager .AlertType .ALERT_TYPE_STORAGE_ALLOCATED ;
656- break ;
657- case Capacity .CAPACITY_TYPE_LOCAL_STORAGE :
658- msgSubject = "System Alert: Remaining unallocated Local Storage is low in cluster " + cluster .getName () + " pod " + pod .getName () + " of availability zone " +
659- dc .getName ();
660- totalStr = formatBytesToMegabytes (totalCapacity );
661- usedStr = formatBytesToMegabytes (usedCapacity );
662- msgContent = "Unallocated storage space is low, total: " + totalStr + " MB, allocated: " + usedStr + " MB (" + pctStr + "%)" ;
663- alertType = AlertManager .AlertType .ALERT_TYPE_LOCAL_STORAGE ;
664- break ;
665-
666- //Pod Level
667- case Capacity .CAPACITY_TYPE_PRIVATE_IP :
668- msgSubject = "System Alert: Number of unallocated private IPs is low in pod " + pod .getName () + " of availability zone " + dc .getName ();
669- totalStr = Double .toString (totalCapacity );
670- usedStr = Double .toString (usedCapacity );
671- msgContent = "Number of unallocated private IPs is low, total: " + totalStr + ", allocated: " + usedStr + " (" + pctStr + "%)" ;
672- alertType = AlertManager .AlertType .ALERT_TYPE_PRIVATE_IP ;
673- break ;
674-
675- //Zone Level
676- case Capacity .CAPACITY_TYPE_SECONDARY_STORAGE :
677- msgSubject = "System Alert: Low Available Secondary Storage in availability zone " + dc .getName ();
678- totalStr = formatBytesToMegabytes (totalCapacity );
679- usedStr = formatBytesToMegabytes (usedCapacity );
680- msgContent = "Available secondary storage space is low, total: " + totalStr + " MB, used: " + usedStr + " MB (" + pctStr + "%)" ;
681- alertType = AlertManager .AlertType .ALERT_TYPE_SECONDARY_STORAGE ;
682- break ;
683- case Capacity .CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP :
684- msgSubject = "System Alert: Number of unallocated virtual network public IPs is low in availability zone " + dc .getName ();
685- totalStr = Double .toString (totalCapacity );
686- usedStr = Double .toString (usedCapacity );
687- msgContent = "Number of unallocated public IPs is low, total: " + totalStr + ", allocated: " + usedStr + " (" + pctStr + "%)" ;
688- alertType = AlertManager .AlertType .ALERT_TYPE_VIRTUAL_NETWORK_PUBLIC_IP ;
689- break ;
690- case Capacity .CAPACITY_TYPE_DIRECT_ATTACHED_PUBLIC_IP :
691- msgSubject = "System Alert: Number of unallocated shared network IPs is low in availability zone " + dc .getName ();
692- totalStr = Double .toString (totalCapacity );
693- usedStr = Double .toString (usedCapacity );
694- msgContent = "Number of unallocated shared network IPs is low, total: " + totalStr + ", allocated: " + usedStr + " (" + pctStr + "%)" ;
695- alertType = AlertManager .AlertType .ALERT_TYPE_DIRECT_ATTACHED_PUBLIC_IP ;
696- break ;
697- case Capacity .CAPACITY_TYPE_VLAN :
698- msgSubject = "System Alert: Number of unallocated VLANs is low in availability zone " + dc .getName ();
699- totalStr = Double .toString (totalCapacity );
700- usedStr = Double .toString (usedCapacity );
701- msgContent = "Number of unallocated VLANs is low, total: " + totalStr + ", allocated: " + usedStr + " (" + pctStr + "%)" ;
702- alertType = AlertManager .AlertType .ALERT_TYPE_VLAN ;
703- break ;
704- case Capacity .CAPACITY_TYPE_VIRTUAL_NETWORK_IPV6_SUBNET :
705- msgSubject = "System Alert: Number of unallocated virtual network guest IPv6 subnets is low in availability zone " + dc .getName ();
706- totalStr = Double .toString (totalCapacity );
707- usedStr = Double .toString (usedCapacity );
708- msgContent = "Number of unallocated virtual network guest IPv6 subnets is low, total: " + totalStr + ", allocated: " + usedStr + " (" + pctStr + "%)" ;
709- alertType = AlertManager .AlertType .ALERT_TYPE_VIRTUAL_NETWORK_IPV6_SUBNET ;
710- break ;
631+ case Capacity .CAPACITY_TYPE_MEMORY :
632+ msgSubject = String .format ("System Alert: Low Available Memory in cluster [%s] pod [%s] of availability zone [%s]." , clusterName , podName , dataCenterName );
633+ msgContent = String .format ("System memory is low, total: %s MB, used: %s MB (%s%%)." , totalInMB , usedInMB , percentual );
634+ alertType = AlertManager .AlertType .ALERT_TYPE_MEMORY ;
635+ break ;
636+ case Capacity .CAPACITY_TYPE_CPU :
637+ msgSubject = String .format ("System Alert: Low Unallocated CPU in cluster [%s] pod [%s] of availability zone [%s]." , clusterName , podName , dataCenterName );
638+ msgContent = String .format ("Unallocated CPU is low, total: %s Mhz, used: %s Mhz (%s%%)." , DfWhole .format (totalCapacity ), DfWhole .format (usedCapacity ), percentual );
639+ alertType = AlertManager .AlertType .ALERT_TYPE_CPU ;
640+ break ;
641+ case Capacity .CAPACITY_TYPE_STORAGE :
642+ msgSubject = String .format ("System Alert: Low Available Storage in cluster [%s] pod [%s] of availability zone [%s]." , clusterName , podName , dataCenterName );
643+ msgContent = String .format ("Available storage space is low, total: %s MB, used: %s MB (%s%%)." , totalInMB , usedInMB , percentual );
644+ alertType = AlertManager .AlertType .ALERT_TYPE_STORAGE ;
645+ break ;
646+ case Capacity .CAPACITY_TYPE_STORAGE_ALLOCATED :
647+ msgSubject = String .format ("System Alert: Remaining unallocated Storage is low in cluster [%s] pod [%s] of availability zone [%s]." , clusterName , podName ,
648+ dataCenterName );
649+ msgContent = String .format ("Unallocated storage space is low, total: %s MB, allocated: %s MB (%s%%)" , totalInMB , usedInMB , percentual );
650+ alertType = AlertManager .AlertType .ALERT_TYPE_STORAGE_ALLOCATED ;
651+ break ;
652+ case Capacity .CAPACITY_TYPE_LOCAL_STORAGE :
653+ msgSubject = String .format ("System Alert: Remaining unallocated Local Storage is low in cluster [%s] pod [%s] of availability zone [%s]." , clusterName , podName ,
654+ dataCenterName );
655+ msgContent = String .format ("Unallocated storage space is low, total: %s MB, allocated: %s MB (%s%%)" , totalInMB , usedInMB , percentual );
656+ alertType = AlertManager .AlertType .ALERT_TYPE_LOCAL_STORAGE ;
657+ break ;
658+ case Capacity .CAPACITY_TYPE_PRIVATE_IP :
659+ msgSubject = String .format ("System Alert: Number of unallocated private IPs is low in pod %s of availability zone [%s]." , podName , dataCenterName );
660+ msgContent = String .format ("Number of unallocated private IPs is low, total: %s, allocated: %s (%s%%)" , totalInString , usedInString , percentual );
661+ alertType = AlertManager .AlertType .ALERT_TYPE_PRIVATE_IP ;
662+ break ;
663+ case Capacity .CAPACITY_TYPE_SECONDARY_STORAGE :
664+ msgSubject = String .format ("System Alert: Low Available Secondary Storage in availability zone [%s]." , dataCenterName );
665+ msgContent = String .format ("Available secondary storage space is low, total: %s MB, used: %s MB (%s%%)." , totalInMB , usedInMB , percentual );
666+ alertType = AlertManager .AlertType .ALERT_TYPE_SECONDARY_STORAGE ;
667+ break ;
668+ case Capacity .CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP :
669+ msgSubject = String .format ("System Alert: Number of unallocated virtual network public IPs is low in availability zone [%s]." , dataCenterName );
670+ msgContent = String .format ("Number of unallocated public IPs is low, total: %s, allocated: %s (%s%%)." , totalInString , usedInString , percentual );
671+ alertType = AlertManager .AlertType .ALERT_TYPE_VIRTUAL_NETWORK_PUBLIC_IP ;
672+ break ;
673+ case Capacity .CAPACITY_TYPE_DIRECT_ATTACHED_PUBLIC_IP :
674+ msgSubject = String .format ("System Alert: Number of unallocated shared network IPs is low in availability zone [%s]." , dataCenterName );
675+ msgContent = String .format ("Number of unallocated shared network IPs is low, total: %s, allocated: %s (%s%%)." , totalInString , usedInString , percentual );
676+ alertType = AlertManager .AlertType .ALERT_TYPE_DIRECT_ATTACHED_PUBLIC_IP ;
677+ break ;
678+ case Capacity .CAPACITY_TYPE_VLAN :
679+ msgSubject = String .format ("System Alert: Number of unallocated VLANs is low in availability zone [%s]." , dataCenterName );
680+ msgContent = String .format ("Number of unallocated VLANs is low, total: %s, allocated: %s (%s%%)." , totalInString , usedInString , percentual );
681+ alertType = AlertManager .AlertType .ALERT_TYPE_VLAN ;
682+ break ;
683+ case Capacity .CAPACITY_TYPE_VIRTUAL_NETWORK_IPV6_SUBNET :
684+ msgSubject = String .format ("System Alert: Number of unallocated virtual network guest IPv6 subnets is low in availability zone [%s]." , dc .getName ());
685+ msgContent = String .format ("Number of unallocated virtual network guest IPv6 subnets is low, total: [%s], allocated: [%s] (%s%%)." , totalInString , usedInString , percentual );
686+ alertType = AlertManager .AlertType .ALERT_TYPE_VIRTUAL_NETWORK_IPV6_SUBNET ;
687+ break ;
711688 }
712689
713690 try {
714- if (logger .isDebugEnabled ()) {
715- logger .debug (msgSubject );
716- logger .debug (msgContent );
717- }
718- sendAlert (alertType , dc , pod , cluster , msgSubject , msgContent );
691+ logger .debug ("Sending alert with subject [{}] and content [{}]." , msgSubject , msgContent );
692+ sendAlert (alertType , dc .getId (), podId , clusterId , msgSubject , msgContent );
719693 } catch (Exception ex ) {
720694 logger .error ("Exception in CapacityChecker" , ex );
721695 }
0 commit comments