com.opsmatters.newrelic.api.model.alerts.conditions.MetricCondition Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of newrelic-api Show documentation
Show all versions of newrelic-api Show documentation
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.
/*
* 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 java.util.List;
import java.util.ArrayList;
/**
* Represents a New Relic metric condition.
*
* @author Gerald Curley (opsmatters)
*/
public abstract class MetricCondition extends TermsCondition
{
private String metric;
private List entities = new ArrayList();
/**
* Default constructor.
*/
public MetricCondition()
{
}
/**
* Sets the metric of the alert condition.
* @param metric The metric of the alert condition
*/
public void setMetric(String metric)
{
this.metric = metric;
}
/**
* Returns the metric of the alert condition.
* @return The metric of the alert condition
*/
public String getMetric()
{
return metric;
}
/**
* Sets the list of entities for the condition.
* @param entities The list of entities
*/
public void setEntities(List entities)
{
this.entities = entities;
}
/**
* Adds an entity to the alert condition.
* @param entity The entity to be added
*/
public void addEntity(long entity)
{
this.entities.add(entity);
}
/**
* Returns the list of entities for the condition.
* @return The list of entities
*/
public List getEntities()
{
return entities;
}
/**
* Returns the array of entities for the condition.
* @return The array of entities
*/
public long[] getEntitiesArray()
{
long[] ret = new long[entities.size()];
for(int i = 0; i < entities.size(); i++)
ret[i] = entities.get(i);
return ret;
}
/**
* Returns a string representation of the object.
*/
@Override
public String toString()
{
return super.toString()
+", metric="+metric
+", entities="+entities;
}
/**
* Builder to make metric condition construction easier.
*/
protected abstract static class Builder>
extends TermsCondition.Builder
{
private MetricCondition condition;
/**
* Sets the alert condition.
* @param condition The alert condition
* @return This object
*/
public B condition(MetricCondition condition)
{
this.condition = condition;
super.condition(condition);
return self();
}
/**
* Sets the metric of the alert condition.
* @param metric The metric of the alert condition
* @return This object
*/
public B metric(String metric)
{
condition.setMetric(metric);
return self();
}
/**
* Sets the entities of the alert condition.
* @param entities The entities of the alert condition
* @return This object
*/
public B entities(List entities)
{
condition.setEntities(entities);
return self();
}
/**
* Adds the entity to the alert condition.
* @param entity The entity to be added
* @return This object
*/
public B addEntity(long entity)
{
condition.addEntity(entity);
return self();
}
}
}