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

com.opsmatters.newrelic.api.model.alerts.conditions.NrqlAlertCondition 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;

/**
 * Represents a New Relic NRQL alert condition.  
 * 
 * @author Gerald Curley (opsmatters)
 */
public class NrqlAlertCondition extends TermsCondition
{
    // The field names
    public static final String VALUE_FUNCTION = "value_function";

    @SerializedName("value_function")
    private String valueFunction;

    private Nrql nrql;

    /**
     * Represents an NRQL alert condition value function.  
     */
    public enum ValueFunction
    {
        SINGLE_VALUE("single_value"),
        SUM("sum");

        ValueFunction(String value)
        {
            this.value = value;
        }

        public String value()
        {
            return value;
        }

        /**
         * Returns the type for the given value.
         * @param value The type value
         * @return The type for the given value
         */
        public static ValueFunction fromValue(String value)
        {
            ValueFunction[] types = values();
            for(ValueFunction type : types)
            {
                if(type.value().equals(value))
                    return type;
            }
            return null;
        }

        /**
         * Returns true if the given value is contained in the list of types.
         * @param value The type value
         * @return true if the given value is contained in the list of types
         */
        public static boolean contains(String value)
        {
            return fromValue(value) != null;
        }

        private String value;
    }

    /**
     * Default constructor.
     */
    public NrqlAlertCondition()
    {
    }
    
    /**
     * Sets the value function of the alert condition.
     * @param valueFunction The value function of the alert condition
     */
    public void setValueFunction(String valueFunction)
    {
        this.valueFunction = valueFunction;
    }

    /**
     * Sets the value function of the alert condition.
     * @param valueFunction The value function of the alert condition
     */
    public void setValueFunction(ValueFunction valueFunction)
    {
        setValueFunction(valueFunction.value());
    }

    /**
     * Returns the value function of the alert condition.
     * @return The value function of the alert condition
     */
    public String getValueFunction()
    {
        return valueFunction;
    }

    /**
     * Sets the nrql of the alert condition.
     * @param nrql The nrql of the alert condition
     */
    public void setNrql(Nrql nrql)
    {
        this.nrql = nrql;
    }

    /**
     * Returns the nrql of the alert condition.
     * @return The nrql of the alert condition
     */
    public Nrql getNrql()
    {
        return nrql;
    }

    /**
     * Returns a string representation of the object.
     */
    @Override
    public String toString()
    {
        return "NrqlAlertCondition ["+super.toString()
            +", valueFunction="+valueFunction
            +", nrql="+nrql
            +"]";
    }

    /**
     * Returns a builder for the NRQL alert condition.
     * @return The builder instance.
     */
    public static Builder builder()
    {
        return new Builder();
    }

    /**
     * Builder to make NRQL alert condition construction easier.
     */
    public static class Builder extends TermsCondition.Builder
    {
        private NrqlAlertCondition condition = new NrqlAlertCondition();

        /**
         * Default constructor.
         */
        public Builder()
        {
            condition(condition);
        }

        /**
         * Sets the value function of the alert condition.
         * @param valueFunction The value function of the alert condition
         * @return This object
         */
        public Builder valueFunction(String valueFunction)
        {
            condition.setValueFunction(valueFunction);
            return this;
        }

        /**
         * Sets the value function of the alert condition to "single_value".
         * @return This object
         */
        public Builder singleValueFunction()
        {
            condition.setValueFunction(ValueFunction.SINGLE_VALUE);
            return this;
        }

        /**
         * Sets the value function of the alert condition to "sum".
         * @return This object
         */
        public Builder sumValueFunction()
        {
            condition.setValueFunction(ValueFunction.SUM);
            return this;
        }

        /**
         * Sets the nrql of the alert condition.
         * @param nrql The nrql of the alert condition
         * @return This object
         */
        public Builder nrql(Nrql nrql)
        {
            condition.setNrql(nrql);
            return this;
        }

        /**
         * Returns this object.
         * @return This object
         */
        @Override
        protected Builder self()
        {
            return this;
        }

        /**
         * Returns the configured alert condition instance
         * @return The alert condition instance
         */
        @Override
        public NrqlAlertCondition build()
        {
            return condition;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy