当前位置: 首页>>代码示例>>Java>>正文


Java Tools.nowUTC方法代码示例

本文整理汇总了Java中org.graylog2.plugin.Tools.nowUTC方法的典型用法代码示例。如果您正苦于以下问题:Java Tools.nowUTC方法的具体用法?Java Tools.nowUTC怎么用?Java Tools.nowUTC使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.graylog2.plugin.Tools的用法示例。


在下文中一共展示了Tools.nowUTC方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: evalErrorSuppressed

import org.graylog2.plugin.Tools; //导入方法依赖的package包/类
@Test
public void evalErrorSuppressed() {
    final Rule rule = parser.parseRule(ruleForTest(), false);

    final Message message = new Message("test", "test", Tools.nowUTC());
    message.addField("this_field_was_set", true);
    final EvaluationContext context = contextForRuleEval(rule, message);

    assertThat(context).isNotNull();
    assertThat(context.hasEvaluationErrors()).isFalse();
    assertThat(actionsTriggered.get()).isTrue();
}
 
开发者ID:Graylog2,项目名称:graylog-plugin-pipeline-processor,代码行数:13,代码来源:FunctionsSnippetsTest.java

示例9: ipMatchingIssue28

import org.graylog2.plugin.Tools; //导入方法依赖的package包/类
@Test
public void ipMatchingIssue28() {
    final Rule rule = parser.parseRule(ruleForTest(), false);
    final Message in = new Message("some message", "somehost.graylog.org", Tools.nowUTC());
    evaluateRule(rule, in);

    assertThat(actionsTriggered.get()).isFalse();
}
 
开发者ID:Graylog2,项目名称:graylog-plugin-pipeline-processor,代码行数:9,代码来源:FunctionsSnippetsTest.java

示例10: fieldRenaming

import org.graylog2.plugin.Tools; //导入方法依赖的package包/类
@Test
public void fieldRenaming() {
    final Rule rule = parser.parseRule(ruleForTest(), false);

    final Message in = new Message("some message", "somehost.graylog.org", Tools.nowUTC());
    in.addField("field_a", "fieldAContent");
    in.addField("field_b", "not deleted");

    final Message message = evaluateRule(rule, in);

    assertThat(message.hasField("field_1")).isFalse();
    assertThat(message.hasField("field_2")).isTrue();
    assertThat(message.hasField("field_b")).isTrue();
}
 
开发者ID:Graylog2,项目名称:graylog-plugin-pipeline-processor,代码行数:15,代码来源:FunctionsSnippetsTest.java

示例11: disabledFilter

import org.graylog2.plugin.Tools; //导入方法依赖的package包/类
@Test
public void disabledFilter() {
    final DnsResolverFilter resolver = new DnsResolverFilter(Period.seconds(1),
                                                                      false,
                                                                      false,
                                                                      metricRegistry);

    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 not be resolved, filter is disabled", "127.0.0.1", msg.getSource());
}
 
开发者ID:graylog-labs,项目名称:graylog-plugin-dnsresolver,代码行数:15,代码来源:DnsResolverFilterTest.java

示例12: lookupsTimeout

import org.graylog2.plugin.Tools; //导入方法依赖的package包/类
@Test
public void lookupsTimeout() {
    final DnsResolverFilter resolver = new DnsResolverFilter(Period.seconds(1),
                                                             false,
                                                             true,
                                                             metricRegistry) {
        @Override
        protected Callable<String> getLookupCallable(String source) {
            return new Callable<String>() {
                @Override
                public String call() throws Exception {
                    Uninterruptibles.sleepUninterruptibly(2, TimeUnit.SECONDS);
                    return "should not be used";
                }
            };
        }
    };

    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);

    assertNotEquals("Late callback results should not be used.", "should not be used", msg.getSource());

    // check for metrics
    assertEquals("should have timed out once", 1, metricRegistry.meter(name(DnsResolverFilter.class, "resolveTimeouts")).getCount());
}
 
开发者ID:graylog-labs,项目名称:graylog-plugin-dnsresolver,代码行数:29,代码来源:DnsResolverFilterTest.java

示例13: runCheck

import org.graylog2.plugin.Tools; //导入方法依赖的package包/类
@Override
  public CheckResult runCheck() {        
      String filter = "streams:" + stream.getId();
      Integer backlogSize = getBacklog();
      boolean backlogEnabled = false;
      int searchLimit = 1;

      if(backlogSize != null && backlogSize > 0) {
          backlogEnabled = true;
          searchLimit = backlogSize;
      }

      SearchResult result = searches.search(
    query,
    filter,
    AbsoluteRange.create(Tools.nowUTC().minus(Minutes.minutes(backtime)).minus(Minutes.minutes(staytime)), Tools.nowUTC().minus(Minutes.minutes(backtime))),
    searchLimit,
    0,
    new Sorting(Message.FIELD_TIMESTAMP, Sorting.Direction.DESC)
);

final List<MessageSummary> summaries;
if (backlogEnabled) {
    summaries = Lists.newArrayListWithCapacity(result.getResults().size());
    for (ResultMessage resultMessage : result.getResults()) {
        final Message msg = resultMessage.getMessage();
        summaries.add(new MessageSummary(resultMessage.getIndex(), msg));
    }
} else {
    summaries = Collections.emptyList();
}

final long count = result.getTotalResults();

final String resultDescription = "Stream received messages matching <" + query + "> "
    + "(Current grace time: " + grace + " minutes)";

if (count > 0) {
    LOG.debug("Alert check <{}> found [{}] messages.", id, count);
    return new CheckResult(true, this, resultDescription, Tools.nowUTC(), summaries);
} else {
    LOG.debug("Alert check <{}> returned no results.", id);
    return new NegativeCheckResult();
}
  }
 
开发者ID:alcampos,项目名称:graylog-plugin-alert-condition-delorean,代码行数:46,代码来源:DeloreanAlertCondition.java

示例14: toGELFMessage

import org.graylog2.plugin.Tools; //导入方法依赖的package包/类
protected byte[] toGELFMessage(final Message message) throws IOException {
    final HashMap<String, Object> fields = new HashMap<>(message.getFields());

    final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(512);
    final JsonFactory jsonFactory = new JsonFactory();
    final JsonGenerator generator = jsonFactory.createGenerator(outputStream);
    generator.writeStartObject();
    generator.writeStringField("version", "1.1");
    generator.writeStringField("host", (String) fields.remove(Message.FIELD_SOURCE));
    generator.writeStringField("short_message", (String) fields.remove(Message.FIELD_MESSAGE));

    final String fullMessage = (String) fields.remove(Message.FIELD_FULL_MESSAGE);
    if (fullMessage != null) {
        generator.writeStringField("full_message", fullMessage);
    }

    final Object fieldTimeStamp = fields.remove(Message.FIELD_TIMESTAMP);
    final DateTime timestamp;
    if (fieldTimeStamp instanceof DateTime) {
        timestamp = (DateTime) fieldTimeStamp;
    } else {
        timestamp = Tools.nowUTC();
    }
    generator.writeNumberField("timestamp", timestamp.getMillis() / 1000d);

    final Object fieldLevel = fields.remove(Message.FIELD_TIMESTAMP);
    final Integer level = extractLevel(fieldLevel);
    if (level != null) {
        generator.writeNumberField("level", level);
    }

    for (Map.Entry<String, Object> field : fields.entrySet()) {
        final String key = field.getKey();
        final Object value = field.getValue();

        if (value instanceof String) {
            generator.writeStringField(key, (String) value);
        } else if (value instanceof Boolean) {
            generator.writeBooleanField(key, (Boolean) value);
        } else if (value instanceof Integer) {
            generator.writeNumberField(key, (Integer) value);
        } else if (value instanceof Long) {
            generator.writeNumberField(key, (Long) value);
        } else if (value instanceof Float) {
            generator.writeNumberField(key, (Float) value);
        } else if (value instanceof Double) {
            generator.writeNumberField(key, (Double) value);
        } else if (value instanceof BigDecimal) {
            generator.writeNumberField(key, (BigDecimal) value);
        } else if (value == null) {
            generator.writeNullField(key);
        }
    }

    generator.writeStringField("_forwarder_cluster_id", clusterId);
    generator.writeStringField("_forwarder_node_id", nodeId);

    generator.writeEndObject();

    generator.flush();

    return outputStream.toByteArray();
}
 
开发者ID:graylog-labs,项目名称:graylog-plugin-redis,代码行数:64,代码来源:GELFRedisOutput.java

示例15: testPipeline

import org.graylog2.plugin.Tools; //导入方法依赖的package包/类
@Benchmark
public Messages testPipeline(final InterpreterState state) {
    Message msg = new Message("original message", "test", Tools.nowUTC());
    return state.interpreter.process(msg);
}
 
开发者ID:Graylog2,项目名称:graylog-plugin-pipeline-processor,代码行数:6,代码来源:FilterchainVsPipeline.java


注:本文中的org.graylog2.plugin.Tools.nowUTC方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。