本文整理汇总了Java中org.graylog2.plugin.Tools类的典型用法代码示例。如果您正苦于以下问题:Java Tools类的具体用法?Java Tools怎么用?Java Tools使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Tools类属于org.graylog2.plugin包,在下文中一共展示了Tools类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: doRun
import org.graylog2.plugin.Tools; //导入依赖的package包/类
@Override
public void doRun()
{
BackupConfiguration info = clusterConfigService.getOrDefault(BackupConfiguration.class, BackupConfiguration.defaultConfig( ));
if (canStartBackup(info))
{
try
{
backupService.start(info);
LOG.info("Backup GrayLog configuration completed ");
BackupConfiguration newInfo = BackupConfiguration.builder( ).enabled(info.enabled( )).scheduledPeriod(info.scheduledPeriod( )).mongoDumpPath(info.mongoDumpPath( )).restorePath(info.restorePath( )).backupPath(info.backupPath( )).lastbackupTime(Tools.nowUTC( )).build( );
clusterConfigService.write(newInfo);
}
catch (BackupException e)
{
LOG.error("", e);
}
}
}
开发者ID:fbalicchia,项目名称:graylog-plugin-backup-configuration,代码行数:21,代码来源:BackupConfigurationPeriodical.java
示例2: canStartBackup
import org.graylog2.plugin.Tools; //导入依赖的package包/类
@Test
public void canStartBackup()
{
final DateTime initialTime = new DateTime(2016, 9, 26, 23, 0, 35, 0, DateTimeZone.UTC);
final InstantMillisProvider clock = new InstantMillisProvider(initialTime);
DateTimeUtils.setCurrentMillisProvider(clock);
BackupConfiguration testinfo = BackupConfiguration.builder( ).enabled(false).scheduledPeriod(Period.days(1))
.mongoDumpPath(StringUtils.EMPTY)
.restorePath(StringUtils.EMPTY)
.backupPath(StringUtils.EMPTY)
.lastbackupTime(Tools.nowUTC( )).build( );
BackupConfigurationPeriodical configuration = new BackupConfigurationPeriodical(null, null);
assertThat(configuration.canStartBackup(testinfo)).isFalse( );
DateTime lastBackup = new DateTime(2016, 9, 26, 22, 56, 0, 0);
testinfo = BackupConfiguration.builder( ).enabled(true).scheduledPeriod(Period.minutes(1)).mongoDumpPath("").restorePath("").backupPath("").lastbackupTime(lastBackup).build( );
assertThat(configuration.canStartBackup(testinfo)).isTrue( );
lastBackup = new DateTime(2016, 9, 26, 23, 2, 0, 0, DateTimeZone.UTC);
testinfo = BackupConfiguration.builder( ).enabled(true).scheduledPeriod(Period.minutes(1)).mongoDumpPath("").restorePath("").backupPath("").lastbackupTime(lastBackup).build( );
assertThat(configuration.canStartBackup(testinfo)).isFalse( );
}
开发者ID:fbalicchia,项目名称:graylog-plugin-backup-configuration,代码行数:27,代码来源:BackConfigurationPeriodicalTest.java
示例3: evaluate
import org.graylog2.plugin.Tools; //导入依赖的package包/类
@Override
public Message evaluate(FunctionArgs args, EvaluationContext context) {
final Optional<String> optMessage = messageParam.optional(args, context);
final String message = optMessage.isPresent() ? optMessage.get() : context.currentMessage().getMessage();
final Optional<String> optSource = sourceParam.optional(args, context);
final String source = optSource.isPresent() ? optSource.get() : context.currentMessage().getSource();
final Optional<DateTime> optTimestamp = timestampParam.optional(args, context);
final DateTime timestamp = optTimestamp.isPresent() ? optTimestamp.get() : Tools.nowUTC();
final Message newMessage = new Message(message, source, timestamp);
// register in context so the processor can inject it later on
context.addCreatedMessage(newMessage);
return newMessage;
}
开发者ID:Graylog2,项目名称:graylog-plugin-pipeline-processor,代码行数:18,代码来源:CreateMessage.java
示例4: newlyCreatedMessage
import org.graylog2.plugin.Tools; //导入依赖的package包/类
@Test
public void newlyCreatedMessage() {
final Message message = new Message("test", "test", Tools.nowUTC());
message.addField("foo", "bar");
message.addStream(mock(Stream.class));
final Rule rule = parser.parseRule(ruleForTest(), false);
final EvaluationContext context = contextForRuleEval(rule, message);
final Message origMessage = context.currentMessage();
final Message newMessage = Iterables.getOnlyElement(context.createdMessages());
assertThat(origMessage).isNotSameAs(newMessage);
assertThat(newMessage.getMessage()).isEqualTo("new");
assertThat(newMessage.getSource()).isEqualTo("synthetic");
assertThat(newMessage.getStreams()).isEmpty();
assertThat(newMessage.hasField("removed_again")).isFalse();
assertThat(newMessage.getFieldAs(Boolean.class, "has_source")).isTrue();
assertThat(newMessage.getFieldAs(String.class, "only_in")).isEqualTo("new message");
assertThat(newMessage.getFieldAs(String.class, "multi")).isEqualTo("new message");
assertThat(newMessage.getFieldAs(String.class, "foo")).isNull();
}
开发者ID:Graylog2,项目名称:graylog-plugin-pipeline-processor,代码行数:22,代码来源:FunctionsSnippetsTest.java
示例5: clonedMessageWithInvalidTimestamp
import org.graylog2.plugin.Tools; //导入依赖的package包/类
@Test
public void clonedMessageWithInvalidTimestamp() {
final Message message = new Message("test", "test", Tools.nowUTC());
message.addField("timestamp", "foobar");
final Rule rule = parser.parseRule(ruleForTest(), false);
final EvaluationContext context = contextForRuleEval(rule, message);
final Message origMessage = context.currentMessage();
final Message clonedMessage = Iterables.get(context.createdMessages(), 0);
assertThat(origMessage).isNotEqualTo(clonedMessage);
assertThat(origMessage.getField("timestamp")).isNotInstanceOf(DateTime.class);
assertThat(clonedMessage).isNotNull();
assertThat(clonedMessage.getMessage()).isEqualTo(origMessage.getMessage());
assertThat(clonedMessage.getSource()).isEqualTo(origMessage.getSource());
assertThat(clonedMessage.getStreams()).isEqualTo(origMessage.getStreams());
assertThat(clonedMessage.getTimestamp()).isNotNull();
assertThat(clonedMessage.getField("gl2_original_timestamp")).isEqualTo(origMessage.getField("timestamp"));
}
开发者ID:Graylog2,项目名称:graylog-plugin-pipeline-processor,代码行数:21,代码来源:FunctionsSnippetsTest.java
示例6: keyValue
import org.graylog2.plugin.Tools; //导入依赖的package包/类
@Test
public void keyValue() {
final Rule rule = parser.parseRule(ruleForTest(), true);
final EvaluationContext context = contextForRuleEval(rule, new Message("", "", Tools.nowUTC()));
assertThat(context).isNotNull();
assertThat(context.evaluationErrors()).isEmpty();
final Message message = context.currentMessage();
assertThat(message).isNotNull();
assertThat(message.getField("a")).isEqualTo("1,4");
assertThat(message.getField("b")).isEqualTo("2");
assertThat(message.getField("c")).isEqualTo("3");
assertThat(message.getField("d")).isEqualTo("44");
assertThat(message.getField("e")).isEqualTo("4");
assertThat(message.getField("f")).isEqualTo("1");
assertThat(message.getField("g")).isEqualTo("3");
assertThat(message.hasField("h")).isFalse();
assertThat(message.getField("dup_first")).isEqualTo("1");
assertThat(message.getField("dup_last")).isEqualTo("2");
}
开发者ID:Graylog2,项目名称:graylog-plugin-pipeline-processor,代码行数:25,代码来源:FunctionsSnippetsTest.java
示例7: AggregatesAlertCondition
import org.graylog2.plugin.Tools; //导入依赖的package包/类
@AssistedInject
public AggregatesAlertCondition(Searches searches,
ClusterConfigService clusterConfigService,
HistoryItemService historyItemService,
@Assisted Stream stream,
@Nullable @Assisted("id") String id,
@Assisted DateTime createdAt,
@Assisted("userid") String creatorUserId,
@Assisted Map<String, Object> parameters,
@Assisted("title") @Nullable String title) {
super(stream, id, AggregatesUtil.ALERT_CONDITION_TYPE, createdAt, creatorUserId, parameters, title);
this.description = (String) parameters.get("description");
this.query = (String) parameters.get("query");
this.field = (String) parameters.get("field");
this.numberOfMatches = (Long)parameters.get("number_of_matches");
this.matchMoreOrEqual = parameters.get("match_more_or_equal") == null ? true : (boolean) parameters.get("match_more_or_equal");
this.searches = searches;
this.limit = 100;
this.interval = Tools.getNumber(parameters.get("interval"), Integer.valueOf(1)).intValue();
this.ruleName = (String) parameters.get("rule_name");
this.clusterConfigService = clusterConfigService;
this.historyItemService= historyItemService;
}
开发者ID:cvtienhoven,项目名称:graylog-plugin-aggregates,代码行数:26,代码来源:AggregatesAlertCondition.java
示例8: filterEnabledAndResolvesLocalhost
import org.graylog2.plugin.Tools; //导入依赖的package包/类
@Test
public void filterEnabledAndResolvesLocalhost() {
final DnsResolverFilter resolver = new DnsResolverFilter(Period.seconds(1),
false,
true,
metricRegistry);
final InetAddress loopbackAddress = Inet4Address.getLoopbackAddress();
final Message msg = new Message("test", "127.0.0.1", Tools.nowUTC());
final boolean filter = resolver.filter(msg);
assertFalse("Message should not be filtered out", filter);
assertEquals("localhost ip should be resolved, filter is enabled", loopbackAddress.getCanonicalHostName(), msg.getSource());
assertEquals("should have looked up one time", 1, metricRegistry.timer(name(DnsResolverFilter.class, "resolveTime")).getCount());
}
开发者ID:graylog-labs,项目名称:graylog-plugin-dnsresolver,代码行数:19,代码来源:DnsResolverFilterTest.java
示例9: ConditionalCountAlertCondition
import org.graylog2.plugin.Tools; //导入依赖的package包/类
@AssistedInject
public ConditionalCountAlertCondition(Searches searches,
Configuration configuration,
@Assisted Stream stream,
@Nullable @Assisted("id") String id,
@Assisted DateTime createdAt,
@Assisted("userid") String creatorUserId,
@Assisted Map<String, Object> parameters,
@Assisted("title") @Nullable String title) {
super(stream, id, ConditionalCountAlertCondition.class.getCanonicalName(), createdAt, creatorUserId, parameters, title);
this.searches = searches;
this.configuration = configuration;
this.query = (String) parameters.get("query");
this.time = Tools.getNumber(parameters.get("time"), 5).intValue();
final String thresholdType = (String) parameters.get("threshold_type");
final String upperCaseThresholdType = thresholdType.toUpperCase(Locale.ENGLISH);
if (!thresholdType.equals(upperCaseThresholdType)) {
final HashMap<String, Object> updatedParameters = new HashMap<>();
updatedParameters.putAll(parameters);
updatedParameters.put("threshold_type", upperCaseThresholdType);
super.setParameters(updatedParameters);
}
this.thresholdType = ThresholdType.valueOf(upperCaseThresholdType);
this.threshold = Tools.getNumber(parameters.get("threshold"), 0).intValue();
}
开发者ID:alcampos,项目名称:graylog-plugin-alert-conditional-count,代码行数:28,代码来源:ConditionalCountAlertCondition.java
示例10: createMessage
import org.graylog2.plugin.Tools; //导入依赖的package包/类
private Message createMessage(String message, Map<String, Object> event) {
@SuppressWarnings("unchecked")
final Map<String, Object> beat = (Map<String, Object>) event.remove("beat");
final String hostname;
final String name;
if (beat == null) {
hostname = "unknown";
name = "unknown";
} else {
hostname = String.valueOf(beat.get("hostname"));
name = String.valueOf(beat.get("name"));
}
final String timestampField = String.valueOf(event.remove("@timestamp"));
final DateTime timestamp = Tools.dateTimeFromString(timestampField);
final String type = String.valueOf(event.get("type"));
final Object tags = event.get("tags");
final Message result = new Message(message, hostname, timestamp);
result.addField("name", name);
result.addField("type", type);
result.addField("tags", tags);
@SuppressWarnings("unchecked")
final Map<String, Object> fields = (Map<String, Object>) event.get("fields");
if (fields != null) {
result.addFields(fields);
}
return result;
}
开发者ID:Graylog2,项目名称:graylog-plugin-beats,代码行数:31,代码来源:BeatsCodec.java
示例11: canStartBackup
import org.graylog2.plugin.Tools; //导入依赖的package包/类
public Boolean canStartBackup(BackupConfiguration backupConfiguration)
{
if (!backupConfiguration.enabled( ))
{
return false;
}
DateTime nextTime = determineRotationPeriodAnchor(backupConfiguration).plus(backupConfiguration.scheduledPeriod( ));
if (nextTime.isAfter(Tools.nowUTC( )))
{
LOG.debug("Next time backup {}", nextTime.toString( ));
}
return backupConfiguration.lastbackupTime( ) == null || !nextTime.isAfterNow( );
}
开发者ID:fbalicchia,项目名称:graylog-plugin-backup-configuration,代码行数:14,代码来源:BackupConfigurationPeriodical.java
示例12: quotedLiteralInFieldRef
import org.graylog2.plugin.Tools; //导入依赖的package包/类
@Test
public void quotedLiteralInFieldRef() {
final Rule rule = parseRule("rule \"test\" when to_string($message.`true`) == \"true\" then end");
final Message message = new Message("hallo", "test", Tools.nowUTC());
message.addField("true", "true");
final Message result = evaluateRule(rule, message);
assertThat(result).isNotNull();
}
开发者ID:Graylog2,项目名称:graylog-plugin-pipeline-processor,代码行数:10,代码来源:PrecedenceTest.java
示例13: create
import org.graylog2.plugin.Tools; //导入依赖的package包/类
@Override
public Stream create(CreateStreamRequest cr, String userId) {
Map<String, Object> streamData = Maps.newHashMap();
streamData.put(StreamImpl.FIELD_TITLE, cr.title());
streamData.put(StreamImpl.FIELD_DESCRIPTION, cr.description());
streamData.put(StreamImpl.FIELD_CREATOR_USER_ID, userId);
streamData.put(StreamImpl.FIELD_CREATED_AT, Tools.nowUTC());
streamData.put(StreamImpl.FIELD_CONTENT_PACK, cr.contentPack());
streamData.put(StreamImpl.FIELD_MATCHING_TYPE, cr.matchingType().toString());
return create(streamData);
}
开发者ID:Graylog2,项目名称:graylog-plugin-pipeline-processor,代码行数:13,代码来源:ConfigurationStateUpdaterTest.java
示例14: testCreateMessage
import org.graylog2.plugin.Tools; //导入依赖的package包/类
@Test
public void testCreateMessage() {
final RuleService ruleService = mock(MongoDbRuleService.class);
when(ruleService.loadAll()).thenReturn(Collections.singleton(
RuleDao.create("abc",
"title",
"description",
"rule \"creates message\"\n" +
"when to_string($message.message) == \"original message\"\n" +
"then\n" +
" create_message(\"derived message\");\n" +
"end",
Tools.nowUTC(),
null)
));
final PipelineService pipelineService = mock(MongoDbPipelineService.class);
when(pipelineService.loadAll()).thenReturn(Collections.singleton(
PipelineDao.create("p1", "title", "description",
"pipeline \"pipeline\"\n" +
"stage 0 match all\n" +
" rule \"creates message\";\n" +
"end\n",
Tools.nowUTC(),
null)
));
final Map<String, Function<?>> functions = ImmutableMap.of(
CreateMessage.NAME, new CreateMessage(),
StringConversion.NAME, new StringConversion());
final PipelineInterpreter interpreter = createPipelineInterpreter(ruleService, pipelineService, functions);
Message msg = messageInDefaultStream("original message", "test");
final Messages processed = interpreter.process(msg);
final Message[] messages = Iterables.toArray(processed, Message.class);
assertEquals(2, messages.length);
}
开发者ID:Graylog2,项目名称:graylog-plugin-pipeline-processor,代码行数:40,代码来源:PipelineInterpreterTest.java
示例15: testMatchAllContinuesIfAllRulesMatched
import org.graylog2.plugin.Tools; //导入依赖的package包/类
@Test
public void testMatchAllContinuesIfAllRulesMatched() {
final RuleService ruleService = mock(MongoDbRuleService.class);
when(ruleService.loadAll()).thenReturn(ImmutableList.of(RULE_TRUE, RULE_FALSE, RULE_ADD_FOOBAR));
final PipelineService pipelineService = mock(MongoDbPipelineService.class);
when(pipelineService.loadAll()).thenReturn(Collections.singleton(
PipelineDao.create("p1", "title", "description",
"pipeline \"pipeline\"\n" +
"stage 0 match all\n" +
" rule \"true\";\n" +
"stage 1 match either\n" +
" rule \"add_foobar\";\n" +
"end\n",
Tools.nowUTC(),
null)
));
final Map<String, Function<?>> functions = ImmutableMap.of(SetField.NAME, new SetField());
final PipelineInterpreter interpreter = createPipelineInterpreter(ruleService, pipelineService, functions);
final Messages processed = interpreter.process(messageInDefaultStream("message", "test"));
final List<Message> messages = ImmutableList.copyOf(processed);
assertThat(messages).hasSize(1);
final Message actualMessage = messages.get(0);
assertThat(actualMessage.getFieldAs(String.class, "foobar")).isEqualTo("covfefe");
}
开发者ID:Graylog2,项目名称:graylog-plugin-pipeline-processor,代码行数:30,代码来源:PipelineInterpreterTest.java
示例16: testMatchAllDoesNotContinueIfNotAllRulesMatched
import org.graylog2.plugin.Tools; //导入依赖的package包/类
@Test
public void testMatchAllDoesNotContinueIfNotAllRulesMatched() {
final RuleService ruleService = mock(MongoDbRuleService.class);
when(ruleService.loadAll()).thenReturn(ImmutableList.of(RULE_TRUE, RULE_FALSE, RULE_ADD_FOOBAR));
final PipelineService pipelineService = mock(MongoDbPipelineService.class);
when(pipelineService.loadAll()).thenReturn(Collections.singleton(
PipelineDao.create("p1", "title", "description",
"pipeline \"pipeline\"\n" +
"stage 0 match all\n" +
" rule \"true\";\n" +
" rule \"false\";\n" +
"stage 1 match either\n" +
" rule \"add_foobar\";\n" +
"end\n",
Tools.nowUTC(),
null)
));
final Map<String, Function<?>> functions = ImmutableMap.of(SetField.NAME, new SetField());
final PipelineInterpreter interpreter = createPipelineInterpreter(ruleService, pipelineService, functions);
final Messages processed = interpreter.process(messageInDefaultStream("message", "test"));
final List<Message> messages = ImmutableList.copyOf(processed);
assertThat(messages).hasSize(1);
final Message actualMessage = messages.get(0);
assertThat(actualMessage.hasField("foobar")).isFalse();
}
开发者ID:Graylog2,项目名称:graylog-plugin-pipeline-processor,代码行数:31,代码来源:PipelineInterpreterTest.java
示例17: testMatchEitherContinuesIfOneRuleMatched
import org.graylog2.plugin.Tools; //导入依赖的package包/类
@Test
public void testMatchEitherContinuesIfOneRuleMatched() {
final RuleService ruleService = mock(MongoDbRuleService.class);
when(ruleService.loadAll()).thenReturn(ImmutableList.of(RULE_TRUE, RULE_FALSE, RULE_ADD_FOOBAR));
final PipelineService pipelineService = mock(MongoDbPipelineService.class);
when(pipelineService.loadAll()).thenReturn(Collections.singleton(
PipelineDao.create("p1", "title", "description",
"pipeline \"pipeline\"\n" +
"stage 0 match either\n" +
" rule \"true\";\n" +
" rule \"false\";\n" +
"stage 1 match either\n" +
" rule \"add_foobar\";\n" +
"end\n",
Tools.nowUTC(),
null)
));
final Map<String, Function<?>> functions = ImmutableMap.of(SetField.NAME, new SetField());
final PipelineInterpreter interpreter = createPipelineInterpreter(ruleService, pipelineService, functions);
final Messages processed = interpreter.process(messageInDefaultStream("message", "test"));
final List<Message> messages = ImmutableList.copyOf(processed);
assertThat(messages).hasSize(1);
final Message actualMessage = messages.get(0);
assertThat(actualMessage.getFieldAs(String.class, "foobar")).isEqualTo("covfefe");
}
开发者ID:Graylog2,项目名称:graylog-plugin-pipeline-processor,代码行数:31,代码来源:PipelineInterpreterTest.java
示例18: testMatchEitherStopsIfNoRuleMatched
import org.graylog2.plugin.Tools; //导入依赖的package包/类
@Test
public void testMatchEitherStopsIfNoRuleMatched() {
final RuleService ruleService = mock(MongoDbRuleService.class);
when(ruleService.loadAll()).thenReturn(ImmutableList.of(RULE_TRUE, RULE_FALSE, RULE_ADD_FOOBAR));
final PipelineService pipelineService = mock(MongoDbPipelineService.class);
when(pipelineService.loadAll()).thenReturn(Collections.singleton(
PipelineDao.create("p1", "title", "description",
"pipeline \"pipeline\"\n" +
"stage 0 match either\n" +
" rule \"false\";\n" +
"stage 1 match either\n" +
" rule \"add_foobar\";\n" +
"end\n",
Tools.nowUTC(),
null)
));
final Map<String, Function<?>> functions = ImmutableMap.of(SetField.NAME, new SetField());
final PipelineInterpreter interpreter = createPipelineInterpreter(ruleService, pipelineService, functions);
final Messages processed = interpreter.process(messageInDefaultStream("message", "test"));
final List<Message> messages = ImmutableList.copyOf(processed);
assertThat(messages).hasSize(1);
final Message actualMessage = messages.get(0);
assertThat(actualMessage.hasField("foobar")).isFalse();
}
开发者ID:Graylog2,项目名称:graylog-plugin-pipeline-processor,代码行数:30,代码来源:PipelineInterpreterTest.java
示例19: messageInDefaultStream
import org.graylog2.plugin.Tools; //导入依赖的package包/类
private Message messageInDefaultStream(String message, String source) {
final Message msg = new Message(message, source, Tools.nowUTC());
final Stream mockedStream = mock(Stream.class);
when(mockedStream.getId()).thenReturn(DEFAULT_STREAM_ID);
msg.addStream(mockedStream);
return msg;
}
开发者ID:Graylog2,项目名称:graylog-plugin-pipeline-processor,代码行数:10,代码来源:PipelineInterpreterTest.java
示例20: ipMatching
import org.graylog2.plugin.Tools; //导入依赖的package包/类
@Test
public void ipMatching() {
final Rule rule = parser.parseRule(ruleForTest(), false);
final Message in = new Message("test", "test", Tools.nowUTC());
in.addField("ip", "192.168.1.20");
final Message message = evaluateRule(rule, in);
assertThat(actionsTriggered.get()).isTrue();
assertThat(message).isNotNull();
assertThat(message.getField("ip_anon")).isEqualTo("192.168.1.0");
assertThat(message.getField("ipv6_anon")).isEqualTo("2001:db8::");
}
开发者ID:Graylog2,项目名称:graylog-plugin-pipeline-processor,代码行数:13,代码来源:FunctionsSnippetsTest.java
注:本文中的org.graylog2.plugin.Tools类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论