@@ -572,105 +572,81 @@ private void generateEmailAlert(DataCenterVO dc, HostPodVO pod, ClusterVO cluste
572572
573573 String msgSubject = null ;
574574 String msgContent = null ;
575- String totalStr ;
576- String usedStr ;
577- String pctStr = formatPercent (usedCapacity / totalCapacity );
575+ String percentual = formatPercent (usedCapacity / totalCapacity );
576+ String totalInMB = formatBytesToMegabytes (totalCapacity );
577+ String usedInMB = formatBytesToMegabytes (usedCapacity );
578+ String totalInString = String .valueOf (totalCapacity );
579+ String usedInString = String .valueOf (usedCapacity );
578580 AlertType alertType = null ;
579581 Long podId = pod == null ? null : pod .getId ();
580582 Long clusterId = cluster == null ? null : cluster .getId ();
583+ String clusterName = cluster == null ? null : cluster .getName ();
584+ String podName = pod == null ? null : pod .getName ();
585+ String dataCenterName = dc .getName ();
581586
582587 switch (capacityType ) {
583-
584- //Cluster Level
585- case Capacity .CAPACITY_TYPE_MEMORY :
586- msgSubject = "System Alert: Low Available Memory in cluster " + cluster .getName () + " pod " + pod .getName () + " of availability zone " + dc .getName ();
587- totalStr = formatBytesToMegabytes (totalCapacity );
588- usedStr = formatBytesToMegabytes (usedCapacity );
589- msgContent = "System memory is low, total: " + totalStr + " MB, used: " + usedStr + " MB (" + pctStr + "%)" ;
590- alertType = AlertManager .AlertType .ALERT_TYPE_MEMORY ;
591- break ;
592- case Capacity .CAPACITY_TYPE_CPU :
593- msgSubject = "System Alert: Low Unallocated CPU in cluster " + cluster .getName () + " pod " + pod .getName () + " of availability zone " + dc .getName ();
594- totalStr = DfWhole .format (totalCapacity );
595- usedStr = DfWhole .format (usedCapacity );
596- msgContent = "Unallocated CPU is low, total: " + totalStr + " Mhz, used: " + usedStr + " Mhz (" + pctStr + "%)" ;
597- alertType = AlertManager .AlertType .ALERT_TYPE_CPU ;
598- break ;
599- case Capacity .CAPACITY_TYPE_STORAGE :
600- msgSubject = "System Alert: Low Available Storage in cluster " + cluster .getName () + " pod " + pod .getName () + " of availability zone " + dc .getName ();
601- totalStr = formatBytesToMegabytes (totalCapacity );
602- usedStr = formatBytesToMegabytes (usedCapacity );
603- msgContent = "Available storage space is low, total: " + totalStr + " MB, used: " + usedStr + " MB (" + pctStr + "%)" ;
604- alertType = AlertManager .AlertType .ALERT_TYPE_STORAGE ;
605- break ;
606- case Capacity .CAPACITY_TYPE_STORAGE_ALLOCATED :
607- msgSubject = "System Alert: Remaining unallocated Storage is low in cluster " + cluster .getName () + " pod " + pod .getName () + " of availability zone " +
608- dc .getName ();
609- totalStr = formatBytesToMegabytes (totalCapacity );
610- usedStr = formatBytesToMegabytes (usedCapacity );
611- msgContent = "Unallocated storage space is low, total: " + totalStr + " MB, allocated: " + usedStr + " MB (" + pctStr + "%)" ;
612- alertType = AlertManager .AlertType .ALERT_TYPE_STORAGE_ALLOCATED ;
613- break ;
614- case Capacity .CAPACITY_TYPE_LOCAL_STORAGE :
615- msgSubject = "System Alert: Remaining unallocated Local Storage is low in cluster " + cluster .getName () + " pod " + pod .getName () + " of availability zone " +
616- dc .getName ();
617- totalStr = formatBytesToMegabytes (totalCapacity );
618- usedStr = formatBytesToMegabytes (usedCapacity );
619- msgContent = "Unallocated storage space is low, total: " + totalStr + " MB, allocated: " + usedStr + " MB (" + pctStr + "%)" ;
620- alertType = AlertManager .AlertType .ALERT_TYPE_LOCAL_STORAGE ;
621- break ;
622-
623- //Pod Level
624- case Capacity .CAPACITY_TYPE_PRIVATE_IP :
625- msgSubject = "System Alert: Number of unallocated private IPs is low in pod " + pod .getName () + " of availability zone " + dc .getName ();
626- totalStr = Double .toString (totalCapacity );
627- usedStr = Double .toString (usedCapacity );
628- msgContent = "Number of unallocated private IPs is low, total: " + totalStr + ", allocated: " + usedStr + " (" + pctStr + "%)" ;
629- alertType = AlertManager .AlertType .ALERT_TYPE_PRIVATE_IP ;
630- break ;
631-
632- //Zone Level
633- case Capacity .CAPACITY_TYPE_SECONDARY_STORAGE :
634- msgSubject = "System Alert: Low Available Secondary Storage in availability zone " + dc .getName ();
635- totalStr = formatBytesToMegabytes (totalCapacity );
636- usedStr = formatBytesToMegabytes (usedCapacity );
637- msgContent = "Available secondary storage space is low, total: " + totalStr + " MB, used: " + usedStr + " MB (" + pctStr + "%)" ;
638- alertType = AlertManager .AlertType .ALERT_TYPE_SECONDARY_STORAGE ;
639- break ;
640- case Capacity .CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP :
641- msgSubject = "System Alert: Number of unallocated virtual network public IPs is low in availability zone " + dc .getName ();
642- totalStr = Double .toString (totalCapacity );
643- usedStr = Double .toString (usedCapacity );
644- msgContent = "Number of unallocated public IPs is low, total: " + totalStr + ", allocated: " + usedStr + " (" + pctStr + "%)" ;
645- alertType = AlertManager .AlertType .ALERT_TYPE_VIRTUAL_NETWORK_PUBLIC_IP ;
646- break ;
647- case Capacity .CAPACITY_TYPE_DIRECT_ATTACHED_PUBLIC_IP :
648- msgSubject = "System Alert: Number of unallocated shared network IPs is low in availability zone " + dc .getName ();
649- totalStr = Double .toString (totalCapacity );
650- usedStr = Double .toString (usedCapacity );
651- msgContent = "Number of unallocated shared network IPs is low, total: " + totalStr + ", allocated: " + usedStr + " (" + pctStr + "%)" ;
652- alertType = AlertManager .AlertType .ALERT_TYPE_DIRECT_ATTACHED_PUBLIC_IP ;
653- break ;
654- case Capacity .CAPACITY_TYPE_VLAN :
655- msgSubject = "System Alert: Number of unallocated VLANs is low in availability zone " + dc .getName ();
656- totalStr = Double .toString (totalCapacity );
657- usedStr = Double .toString (usedCapacity );
658- msgContent = "Number of unallocated VLANs is low, total: " + totalStr + ", allocated: " + usedStr + " (" + pctStr + "%)" ;
659- alertType = AlertManager .AlertType .ALERT_TYPE_VLAN ;
660- break ;
661- case Capacity .CAPACITY_TYPE_VIRTUAL_NETWORK_IPV6_SUBNET :
662- msgSubject = "System Alert: Number of unallocated virtual network guest IPv6 subnets is low in availability zone " + dc .getName ();
663- totalStr = Double .toString (totalCapacity );
664- usedStr = Double .toString (usedCapacity );
665- msgContent = "Number of unallocated virtual network guest IPv6 subnets is low, total: " + totalStr + ", allocated: " + usedStr + " (" + pctStr + "%)" ;
666- alertType = AlertManager .AlertType .ALERT_TYPE_VIRTUAL_NETWORK_IPV6_SUBNET ;
667- break ;
588+ case Capacity .CAPACITY_TYPE_MEMORY :
589+ msgSubject = String .format ("System Alert: Low Available Memory in cluster [%s] pod [%s] of availability zone [%s]." , clusterName , podName , dataCenterName );
590+ msgContent = String .format ("System memory is low, total: %s MB, used: %s MB (%s%%)." , totalInMB , usedInMB , percentual );
591+ alertType = AlertManager .AlertType .ALERT_TYPE_MEMORY ;
592+ break ;
593+ case Capacity .CAPACITY_TYPE_CPU :
594+ msgSubject = String .format ("System Alert: Low Unallocated CPU in cluster [%s] pod [%s] of availability zone [%s]." , clusterName , podName , dataCenterName );
595+ msgContent = String .format ("Unallocated CPU is low, total: %s Mhz, used: %s Mhz (%s%%)." , DfWhole .format (totalCapacity ), DfWhole .format (usedCapacity ), percentual );
596+ alertType = AlertManager .AlertType .ALERT_TYPE_CPU ;
597+ break ;
598+ case Capacity .CAPACITY_TYPE_STORAGE :
599+ msgSubject = String .format ("System Alert: Low Available Storage in cluster [%s] pod [%s] of availability zone [%s]." , clusterName , podName , dataCenterName );
600+ msgContent = String .format ("Available storage space is low, total: %s MB, used: %s MB (%s%%)." , totalInMB , usedInMB , percentual );
601+ alertType = AlertManager .AlertType .ALERT_TYPE_STORAGE ;
602+ break ;
603+ case Capacity .CAPACITY_TYPE_STORAGE_ALLOCATED :
604+ msgSubject = String .format ("System Alert: Remaining unallocated Storage is low in cluster [%s] pod [%s] of availability zone [%s]." , clusterName , podName ,
605+ dataCenterName );
606+ msgContent = String .format ("Unallocated storage space is low, total: %s MB, allocated: %s MB (%s%%)" , totalInMB , usedInMB , percentual );
607+ alertType = AlertManager .AlertType .ALERT_TYPE_STORAGE_ALLOCATED ;
608+ break ;
609+ case Capacity .CAPACITY_TYPE_LOCAL_STORAGE :
610+ msgSubject = String .format ("System Alert: Remaining unallocated Local Storage is low in cluster [%s] pod [%s] of availability zone [%s]." , clusterName , podName ,
611+ dataCenterName );
612+ msgContent = String .format ("Unallocated storage space is low, total: %s MB, allocated: %s MB (%s%%)" , totalInMB , usedInMB , percentual );
613+ alertType = AlertManager .AlertType .ALERT_TYPE_LOCAL_STORAGE ;
614+ break ;
615+ case Capacity .CAPACITY_TYPE_PRIVATE_IP :
616+ msgSubject = String .format ("System Alert: Number of unallocated private IPs is low in pod %s of availability zone [%s]." , podName , dataCenterName );
617+ msgContent = String .format ("Number of unallocated private IPs is low, total: %s, allocated: %s (%s%%)" , totalInString , usedInString , percentual );
618+ alertType = AlertManager .AlertType .ALERT_TYPE_PRIVATE_IP ;
619+ break ;
620+ case Capacity .CAPACITY_TYPE_SECONDARY_STORAGE :
621+ msgSubject = String .format ("System Alert: Low Available Secondary Storage in availability zone [%s]." , dataCenterName );
622+ msgContent = String .format ("Available secondary storage space is low, total: %s MB, used: %s MB (%s%%)." , totalInMB , usedInMB , percentual );
623+ alertType = AlertManager .AlertType .ALERT_TYPE_SECONDARY_STORAGE ;
624+ break ;
625+ case Capacity .CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP :
626+ msgSubject = String .format ("System Alert: Number of unallocated virtual network public IPs is low in availability zone [%s]." , dataCenterName );
627+ msgContent = String .format ("Number of unallocated public IPs is low, total: %s, allocated: %s (%s%%)." , totalInString , usedInString , percentual );
628+ alertType = AlertManager .AlertType .ALERT_TYPE_VIRTUAL_NETWORK_PUBLIC_IP ;
629+ break ;
630+ case Capacity .CAPACITY_TYPE_DIRECT_ATTACHED_PUBLIC_IP :
631+ msgSubject = String .format ("System Alert: Number of unallocated shared network IPs is low in availability zone [%s]." , dataCenterName );
632+ msgContent = String .format ("Number of unallocated shared network IPs is low, total: %s, allocated: %s (%s%%)." , totalInString , usedInString , percentual );
633+ alertType = AlertManager .AlertType .ALERT_TYPE_DIRECT_ATTACHED_PUBLIC_IP ;
634+ break ;
635+ case Capacity .CAPACITY_TYPE_VLAN :
636+ msgSubject = String .format ("System Alert: Number of unallocated VLANs is low in availability zone [%s]." , dataCenterName );
637+ msgContent = String .format ("Number of unallocated VLANs is low, total: %s, allocated: %s (%s%%)." , totalInString , usedInString , percentual );
638+ alertType = AlertManager .AlertType .ALERT_TYPE_VLAN ;
639+ break ;
640+ case Capacity .CAPACITY_TYPE_VIRTUAL_NETWORK_IPV6_SUBNET :
641+ msgSubject = String .format ("System Alert: Number of unallocated virtual network guest IPv6 subnets is low in availability zone [%s]." , dc .getName ());
642+ msgContent = String .format ("Number of unallocated virtual network guest IPv6 subnets is low, total: [%s], allocated: [%s] (%s%%)." , totalInString , usedInString , percentual );
643+ alertType = AlertManager .AlertType .ALERT_TYPE_VIRTUAL_NETWORK_IPV6_SUBNET ;
644+ break ;
668645 }
669646
670647 try {
671648 if (logger .isDebugEnabled ()) {
672- logger .debug (msgSubject );
673- logger .debug (msgContent );
649+ logger .debug (String .format ("Sending alert with subject [%s] and content [%s]." , msgSubject , msgContent ));
674650 }
675651 sendAlert (alertType , dc .getId (), podId , clusterId , msgSubject , msgContent );
676652 } catch (Exception ex ) {
0 commit comments