Develop > Service Health > Service Health Rules API > Examples - API Group and Sibling Rule > Example - Sibling Rule Based on Availability and Performance KPIs

Example - Sibling Rule Based on Availability and Performance KPIs

The following rule calculates KPI status based on the status of sibling Availability and Performance KPIs.

If these KPIs do not exist or do not have active status, no status is set.

If these sibling KPIs exist and are both OK, the calculated KPI status is set to OK. Otherwise, its status is set to Critical. (Active statuses are Critical, Major, Minor, Warning, and OK.)

public void calculateKPI(CI ci, KPI kpi) {
    /**
     * Get the sibling KPI of type Availability.
     * If Availability KPI does not exist, null will be returned.
     */
    KPI availabilityKPI = ci.getKPI(KpiType.Availability);
    // Get the sibling KPI of type Performance.
    KPI performanceKPI = ci.getKPI(KpiType.Performance);
    if (availabilityKPI != null && performanceKPI != null) {
        // Both KPIs exist for this CI. Check if the KPIs status is active.
        if (availabilityKPI.status.isActive() && performanceKPI.status.isActive()) {
            // Check the KPI's status.
            if (availabilityKPI.status == Status.OK &&
                performanceKPI.status == Status.OK) {
                /**
                 * Both statuses are active and both are OK. Set this KPI's status to OK.
                 */
                kpi.status = Status.OK
            }
            else {
                /**
                 * Both statuses are active, and not both are OK.
                 * Set this KPI's status to CRITICAL
                 */
                kpi.status = Status.CRITICAL
            }
        }
    }
}


Parent topic: Examples - API Group and Sibling Rule