Example - Worst Sibling Status Rule

The following rule finds the worst status from sibling KPIs, based on active statuses only. Active statuses are Critical, Major, Minor, Warning, and OK.

public void calculateKPI(CI ci, KPI kpi) {
    // Get a list of all the KPIs for the CI.
    List<KPI> ciKpiList = ci.getAllKPIs();
    /**
     * Create a variable to set the status of the calculated KPI,
     * only if an active status is found.
     */
    boolean isActiveStatusFound = false;
    // Set the current worst status to OK; if a worse status is found this will be updated.
    Status worstStatus = Status.OK;
    // Go over the list of the CI's KPIs.
    ciKpiList.each {KPI ciKPI ->
        /**
        * Check that the CI's KPI is not the calculated KPI.
        * This is needed because getAllKPIs method returns all the KPIs for the CI.
        */
        if (ciKPI !=  kpi) {
            /**
             * The ciKPI represents a sibling KPI of the calculated KPI.
             * Get the sibling KPI's status.
             */
            Status siblingKpiStatus = ciKPI.status;
            // Update worstStatus if necessary.
            if (siblingKpiStatus.isActive()) {
                isActiveStatusFound = true;
                if (siblingKpiStatus.isWorse(worstStatus)) {
                    worstStatus = siblingKpiStatus;
                 }
            }
        }
    }
    // Check if an active status was found in the sibling KPI.
    if (isActiveStatusFound) {
        // Set the calculated KPI's status.
        kpi.setStatus(worstStatus);
    }
}


Parent topic: Examples - API Group and Sibling Rule