Skip to content

Commit

Permalink
Field Content Value rebranding
Browse files Browse the repository at this point in the history
  • Loading branch information
Jochen Schalanda committed May 27, 2015
1 parent 484aca4 commit 12bfc0c
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 34 deletions.
Expand Up @@ -26,19 +26,16 @@
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.Map; import java.util.Map;


/**
* @author Lennart Koopmann <lennart@torch.sh>
*/
public class AlertCondition { public class AlertCondition {


public interface Factory { public interface Factory {
public AlertCondition fromSummaryResponse(AlertConditionSummaryResponse acsr); AlertCondition fromSummaryResponse(AlertConditionSummaryResponse acsr);
} }


public enum Type { public enum Type {
MESSAGE_COUNT, MESSAGE_COUNT,
FIELD_VALUE, FIELD_VALUE,
FIELD_STRING_VALUE FIELD_CONTENT_VALUE
} }


private final String id; private final String id;
Expand Down Expand Up @@ -88,8 +85,8 @@ public String getSummary() {
return "Message count condition"; return "Message count condition";
case FIELD_VALUE: case FIELD_VALUE:
return "Field value condition"; return "Field value condition";
case FIELD_STRING_VALUE: case FIELD_CONTENT_VALUE:
return "Field string value condition"; return "Field content value condition";
} }


throw new RuntimeException("Cannot build summary for unknown alert condition type [" + type + "]"); throw new RuntimeException("Cannot build summary for unknown alert condition type [" + type + "]");
Expand All @@ -109,8 +106,8 @@ public String getDescription() {
case FIELD_VALUE: case FIELD_VALUE:
sb.append(buildFieldValueDescription()); sb.append(buildFieldValueDescription());
break; break;
case FIELD_STRING_VALUE: case FIELD_CONTENT_VALUE:
sb.append(buildFieldStringValueDescription()); sb.append(buildFieldContentValueDescription());
break; break;
default: default:
throw new RuntimeException("Cannot build description for unknown alert condition type [" + type + "]"); throw new RuntimeException("Cannot build description for unknown alert condition type [" + type + "]");
Expand All @@ -122,7 +119,7 @@ public String getDescription() {
return sb.toString(); return sb.toString();
} }


private String buildFieldStringValueDescription() { private String buildFieldContentValueDescription() {
String query = String.valueOf(parameters.get("field")) + ":\"" + parameters.get("value") + "\""; String query = String.valueOf(parameters.get("field")) + ":\"" + parameters.get("value") + "\"";


return "Alert is triggered when messages matching <" + query + "> are received. "; return "Alert is triggered when messages matching <" + query + "> are received. ";
Expand Down
Expand Up @@ -36,7 +36,7 @@ public abstract class AbstractAlertCondition implements EmbeddedPersistable, Ale
public enum Type { public enum Type {
MESSAGE_COUNT, MESSAGE_COUNT,
FIELD_VALUE, FIELD_VALUE,
FIELD_STRING_VALUE, FIELD_CONTENT_VALUE,
DUMMY DUMMY
} }


Expand Down
Expand Up @@ -23,7 +23,7 @@
import com.mongodb.DBObject; import com.mongodb.DBObject;
import com.mongodb.QueryBuilder; import com.mongodb.QueryBuilder;
import org.bson.types.ObjectId; import org.bson.types.ObjectId;
import org.graylog2.alerts.types.FieldStringValueAlertCondition; import org.graylog2.alerts.types.FieldContentValueAlertCondition;
import org.graylog2.alerts.types.FieldValueAlertCondition; import org.graylog2.alerts.types.FieldValueAlertCondition;
import org.graylog2.alerts.types.MessageCountAlertCondition; import org.graylog2.alerts.types.MessageCountAlertCondition;
import org.graylog2.database.MongoConnection; import org.graylog2.database.MongoConnection;
Expand All @@ -47,17 +47,17 @@ public class AlertServiceImpl extends PersistedServiceImpl implements AlertServi


private final FieldValueAlertCondition.Factory fieldValueAlertFactory; private final FieldValueAlertCondition.Factory fieldValueAlertFactory;
private final MessageCountAlertCondition.Factory messageCountAlertFactory; private final MessageCountAlertCondition.Factory messageCountAlertFactory;
private final FieldStringValueAlertCondition.Factory fieldStringValueAlertFactory; private final FieldContentValueAlertCondition.Factory fieldContentValueAlertFactory;


@Inject @Inject
public AlertServiceImpl(MongoConnection mongoConnection, public AlertServiceImpl(MongoConnection mongoConnection,
FieldValueAlertCondition.Factory fieldValueAlertFactory, FieldValueAlertCondition.Factory fieldValueAlertFactory,
MessageCountAlertCondition.Factory messageCountAlertFactory, MessageCountAlertCondition.Factory messageCountAlertFactory,
FieldStringValueAlertCondition.Factory fieldStringValueAlertFactory) { FieldContentValueAlertCondition.Factory fieldContentValueAlertFactory) {
super(mongoConnection); super(mongoConnection);
this.fieldValueAlertFactory = fieldValueAlertFactory; this.fieldValueAlertFactory = fieldValueAlertFactory;
this.messageCountAlertFactory = messageCountAlertFactory; this.messageCountAlertFactory = messageCountAlertFactory;
this.fieldStringValueAlertFactory = fieldStringValueAlertFactory; this.fieldContentValueAlertFactory = fieldContentValueAlertFactory;
} }


@Override @Override
Expand Down Expand Up @@ -153,8 +153,8 @@ private AbstractAlertCondition createAlertCondition(AbstractAlertCondition.Type
return messageCountAlertFactory.createAlertCondition(stream, id, createdAt, creatorId, parameters); return messageCountAlertFactory.createAlertCondition(stream, id, createdAt, creatorId, parameters);
case FIELD_VALUE: case FIELD_VALUE:
return fieldValueAlertFactory.createAlertCondition(stream, id, createdAt, creatorId, parameters); return fieldValueAlertFactory.createAlertCondition(stream, id, createdAt, creatorId, parameters);
case FIELD_STRING_VALUE: case FIELD_CONTENT_VALUE:
return fieldStringValueAlertFactory.createAlertCondition(stream, id, createdAt, creatorId, parameters); return fieldContentValueAlertFactory.createAlertCondition(stream, id, createdAt, creatorId, parameters);
} }


throw new AbstractAlertCondition.NoSuchAlertConditionTypeException("Unhandled alert condition type: " + type); throw new AbstractAlertCondition.NoSuchAlertConditionTypeException("Unhandled alert condition type: " + type);
Expand Down
Expand Up @@ -41,21 +41,21 @@
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;


public class FieldStringValueAlertCondition extends AbstractAlertCondition { public class FieldContentValueAlertCondition extends AbstractAlertCondition {
private static final Logger LOG = LoggerFactory.getLogger(FieldStringValueAlertCondition.class); private static final Logger LOG = LoggerFactory.getLogger(FieldContentValueAlertCondition.class);


private final Searches searches; private final Searches searches;
private final Configuration configuration; private final Configuration configuration;
private final String field; private final String field;
private final String value; private final String value;


public interface Factory { public interface Factory {
FieldStringValueAlertCondition createAlertCondition(Stream stream, String id, DateTime createdAt, @Assisted("userid") String creatorUserId, Map<String, Object> parameters); FieldContentValueAlertCondition createAlertCondition(Stream stream, String id, DateTime createdAt, @Assisted("userid") String creatorUserId, Map<String, Object> parameters);
} }


@AssistedInject @AssistedInject
public FieldStringValueAlertCondition(Searches searches, Configuration configuration, @Assisted Stream stream, @Nullable @Assisted String id, @Assisted DateTime createdAt, @Assisted("userid") String creatorUserId, @Assisted Map<String, Object> parameters) { public FieldContentValueAlertCondition(Searches searches, Configuration configuration, @Assisted Stream stream, @Nullable @Assisted String id, @Assisted DateTime createdAt, @Assisted("userid") String creatorUserId, @Assisted Map<String, Object> parameters) {
super(stream, id, Type.FIELD_STRING_VALUE, createdAt, creatorUserId, parameters); super(stream, id, Type.FIELD_CONTENT_VALUE, createdAt, creatorUserId, parameters);
this.searches = searches; this.searches = searches;
this.configuration = configuration; this.configuration = configuration;
this.field = (String) parameters.get("field"); this.field = (String) parameters.get("field");
Expand Down
Expand Up @@ -28,7 +28,7 @@
import org.graylog2.Configuration; import org.graylog2.Configuration;
import org.graylog2.alerts.AlertSender; import org.graylog2.alerts.AlertSender;
import org.graylog2.alerts.FormattedEmailAlertSender; import org.graylog2.alerts.FormattedEmailAlertSender;
import org.graylog2.alerts.types.FieldStringValueAlertCondition; import org.graylog2.alerts.types.FieldContentValueAlertCondition;
import org.graylog2.alerts.types.FieldValueAlertCondition; import org.graylog2.alerts.types.FieldValueAlertCondition;
import org.graylog2.alerts.types.MessageCountAlertCondition; import org.graylog2.alerts.types.MessageCountAlertCondition;
import org.graylog2.bindings.providers.BundleExporterProvider; import org.graylog2.bindings.providers.BundleExporterProvider;
Expand Down Expand Up @@ -139,7 +139,7 @@ private void bindFactoryModules() {
install(new FactoryModuleBuilder().build(LdapSettingsImpl.Factory.class)); install(new FactoryModuleBuilder().build(LdapSettingsImpl.Factory.class));
install(new FactoryModuleBuilder().build(FieldValueAlertCondition.Factory.class)); install(new FactoryModuleBuilder().build(FieldValueAlertCondition.Factory.class));
install(new FactoryModuleBuilder().build(MessageCountAlertCondition.Factory.class)); install(new FactoryModuleBuilder().build(MessageCountAlertCondition.Factory.class));
install(new FactoryModuleBuilder().build(FieldStringValueAlertCondition.Factory.class)); install(new FactoryModuleBuilder().build(FieldContentValueAlertCondition.Factory.class));
install(new FactoryModuleBuilder().build(WidgetCacheTime.Factory.class)); install(new FactoryModuleBuilder().build(WidgetCacheTime.Factory.class));
} }


Expand Down
Expand Up @@ -18,7 +18,7 @@


import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.inject.assistedinject.Assisted; import com.google.inject.assistedinject.Assisted;
import org.graylog2.alerts.types.FieldStringValueAlertCondition; import org.graylog2.alerts.types.FieldContentValueAlertCondition;
import org.graylog2.alerts.types.FieldValueAlertCondition; import org.graylog2.alerts.types.FieldValueAlertCondition;
import org.graylog2.alerts.types.MessageCountAlertCondition; import org.graylog2.alerts.types.MessageCountAlertCondition;
import org.graylog2.database.MongoConnection; import org.graylog2.database.MongoConnection;
Expand Down Expand Up @@ -84,14 +84,14 @@ public MessageCountAlertCondition createAlertCondition(Stream stream,
return new MessageCountAlertCondition(searches, stream, id, createdAt, creatorUserId, parameters); return new MessageCountAlertCondition(searches, stream, id, createdAt, creatorUserId, parameters);
} }
}, },
new FieldStringValueAlertCondition.Factory() { new FieldContentValueAlertCondition.Factory() {
@Override @Override
public FieldStringValueAlertCondition createAlertCondition(Stream stream, public FieldContentValueAlertCondition createAlertCondition(Stream stream,
String id, String id,
DateTime createdAt, DateTime createdAt,
@Assisted("userid") String creatorUserId, @Assisted("userid") String creatorUserId,
Map<String, Object> parameters) { Map<String, Object> parameters) {
return new FieldStringValueAlertCondition(searches, null, stream, id, createdAt, creatorUserId, parameters); return new FieldContentValueAlertCondition(searches, null, stream, id, createdAt, creatorUserId, parameters);
} }
})); }));


Expand Down
Expand Up @@ -48,13 +48,13 @@
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;


public class FieldStringValueAlertConditionTest extends AlertConditionTest { public class FieldContentValueAlertConditionTest extends AlertConditionTest {


@Test @Test
public void testConstructor() throws Exception { public void testConstructor() throws Exception {
final Map<String, Object> parameters = getParametersMap(0, "field", "value"); final Map<String, Object> parameters = getParametersMap(0, "field", "value");


final FieldStringValueAlertCondition condition = getCondition(parameters); final FieldContentValueAlertCondition condition = getCondition(parameters);


assertNotNull(condition); assertNotNull(condition);
assertNotNull(condition.getDescription()); assertNotNull(condition.getDescription());
Expand Down Expand Up @@ -91,7 +91,7 @@ public void testRunMatchingMessagesInStream() throws Exception {
anyInt(), anyInt(),
any(Sorting.class))) any(Sorting.class)))
.thenReturn(searchResult); .thenReturn(searchResult);
final FieldStringValueAlertCondition condition = getCondition(getParametersMap(0, "message", "something")); final FieldContentValueAlertCondition condition = getCondition(getParametersMap(0, "message", "something"));


alertLastTriggered(-1); alertLastTriggered(-1);


Expand Down Expand Up @@ -124,7 +124,7 @@ public void testRunNoMatchingMessages() throws Exception {
anyInt(), anyInt(),
any(Sorting.class))) any(Sorting.class)))
.thenReturn(searchResult); .thenReturn(searchResult);
final FieldStringValueAlertCondition condition = getCondition(getParametersMap(0, "message", "something")); final FieldContentValueAlertCondition condition = getCondition(getParametersMap(0, "message", "something"));


alertLastTriggered(-1); alertLastTriggered(-1);


Expand All @@ -133,8 +133,8 @@ public void testRunNoMatchingMessages() throws Exception {
assertNotTriggered(result); assertNotTriggered(result);
} }


protected FieldStringValueAlertCondition getCondition(Map<String, Object> parameters) { protected FieldContentValueAlertCondition getCondition(Map<String, Object> parameters) {
return new FieldStringValueAlertCondition( return new FieldContentValueAlertCondition(
searches, searches,
mock(Configuration.class), mock(Configuration.class),
stream, stream,
Expand Down

0 comments on commit 12bfc0c

Please sign in to comment.