All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.opsmatters.newrelic.api.model.alerts.conditions.BaseCondition Maven / Gradle / Ivy

Go to download

Java client library for the New Relic REST APIs built using Jersey and Gson. The library includes over 110 operations across all of the available 35 New Relic services. It can be used by applications to automate the configuration of New Relic Monitoring, Alerting and Dashboards, but can also be used for extracting incident and metric data, executing Insights queries, and uploading plugin metrics.

There is a newer version: 1.0.12
Show newest version
/*
 * Copyright 2018 Gerald Curley
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.opsmatters.newrelic.api.model.alerts.conditions;

import com.google.gson.annotations.SerializedName;
import com.opsmatters.newrelic.api.model.NamedIdResource;

/**
 * Represents the base class for all New Relic alert conditions.  
 * 
 * @author Gerald Curley (opsmatters)
 */
public abstract class BaseCondition extends NamedIdResource
{
    // The field names
    public static final String NAME = "name";
    public static final String ENABLED = "enabled";
    public static final String RUNBOOK_URL = "runbook_url";
    public static final String POLICY_ID = "policy_id";
    public static final String POLICY_NAME = "policy_name";
    public static final String CONDITION_TYPE = "condition_type";

    private Boolean enabled;

    @SerializedName("runbook_url")
    private String runbookUrl;

    protected transient Long policyId;
    
    /**
     * Default constructor.
     */
    public BaseCondition()
    {
    }
    
    /**
     * Set to true if the alert condition is enabled.
     * @param enabled true if the alert condition is enabled
     */
    public void setEnabled(Boolean enabled)
    {
        this.enabled = enabled;
    }

    /**
     * Returns true if the alert condition is enabled.
     * @return true if the alert condition is enabled
     */
    public Boolean getEnabled()
    {
        return enabled;
    }

    /**
     * Sets the runbook URL of the alert condition.
     * @param runbookUrl The runbook URL of the alert condition
     */
    public void setRunbookUrl(String runbookUrl)
    {
        this.runbookUrl = runbookUrl;
    }

    /**
     * Returns the runbook URL of the alert condition.
     * @return The runbook URL of the alert condition
     */
    public String getRunbookUrl()
    {
        return runbookUrl;
    }

    /**
     * Sets the policy id of the alert condition.
     * @param policyId The policy id of the alert condition
     */
    public void setPolicyId(Long policyId)
    {
        this.policyId = policyId;
    }

    /**
     * Returns the policy id of the alert condition.
     * @return The policy id of the alert condition
     */
    public Long getPolicyId()
    {
        return policyId;
    }

    /**
     * Returns a string representation of the object.
     */
    @Override
    public String toString()
    {
        return super.toString()
            +", enabled="+enabled
            +", runbookUrl="+runbookUrl;
    }

    /**
     * Builder to make condition construction easier.
     */
    protected abstract static class Builder>
    {
        private BaseCondition condition;

        /**
         * Sets the alert condition.
         * @param condition The alert condition
         * @return This object
         */
        public B condition(BaseCondition condition)
        {
            this.condition = condition;
            return self();
        }

        /**
         * Sets the id of the alert condition.
         * @param id The id of the alert condition
         * @return This object
         */
        public B id(long id)
        {
            condition.setId(id);
            return self();
        }

        /**
         * Sets the name of the alert condition.
         * @param name The name of the alert condition
         * @return This object
         */
        public B name(String name)
        {
            condition.setName(name);
            return self();
        }

        /**
         * Set to true if the alert condition is enabled.
         * @param enabled true if the alert condition is enabled
         * @return This object
         */
        public B enabled(boolean enabled)
        {
            condition.setEnabled(enabled);
            return self();
        }

        /**
         * Returns this object.
         * @return This object
         */
        protected abstract B self();

        /**
         * Returns the configured alert condition instance
         * @return The alert condition instance
         */
        public abstract T build();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy