Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Splunk HttpEventCollectorLogbackAppender how to set source and host?

I'm using the Splunk HttpEventCollectorLogbackAppender to automatically send application logs to Splunk. I've been trying to set the host, source, and sourcetype but am not having any luck getting them sent to Splunk.

Is it possible to set the host, source, or sourcetype using the Splunk HttpEventCollectorLogbackAppender and if so, how do I do it?

I've been trying to send JSON and it doesn't seem to be working.

Here's the documentation that tells you what options are available and it says that they need to be passed as a query string, but since i'm using the out of the box Splunk appender i'm not sure how to set those.

http://dev.splunk.com/view/event-collector/SP-CAAAE6P

Splunk logback appender:

...
<!-- SPLUNK appender -->
  <appender name="SPLUNK" class="com.splunk.logging.HttpEventCollectorLogbackAppender">
    <url>http://myurl:8088</url>
    <token>mytoken</token>
    <disableCertificateValidation>true</disableCertificateValidation>
    <batch_size_count>1</batch_size_count>
    <layout class="ch.qos.logback.classic.PatternLayout">
      <pattern>%logger: %msg%n</pattern>
    </layout>
  </appender>

<root level="INFO">
  <appender-ref ref="SPLUNK"/>
</root>
...

Example log line

Logger logger = LoggerFactory.getLogger(MyClass.class);
logger.debug("I'm logging debug stuff"); 
like image 226
Catfish Avatar asked Dec 06 '16 21:12

Catfish


1 Answers

Any setters on HttpEventCollectorLogbackAppender can be added to your logback configuration.

So to invoke setHost, setSource and setSourcetype you add them to your logback configuration like this:

<appender name="SPLUNK" class="com.splunk.logging.HttpEventCollectorLogbackAppender">
    <url>http://myurl:8088</url>
    <host>x</host>
    <source>y</source>
    <sourcetype>z</sourcetype>
    <token>mytoken</token>
    <disableCertificateValidation>true</disableCertificateValidation>
    <batch_size_count>1</batch_size_count>
    <layout class="ch.qos.logback.classic.PatternLayout">
        <pattern>%logger: %msg%n</pattern>
    </layout>
</appender>
like image 102
roby Avatar answered Sep 19 '22 14:09

roby