Getting OSSEC Server Logs into ELK stack

Monitoring logs is an important part of active defense. With that being said OSSEC is an industry-standard for HIDS, as being used by many popular commercial tools like Alienvault OSSIM and USM.

Searching through the internet you will find official OSSEC web interface. But it cannot be of much use if you are looking forward to doing some threat hunting or wanted to search through some logs. Now let’s start with a tutorial to integrate OSSEC with ELK stack.

NOTE:- This tutorial is tested for centos 7 only.

Let’s start with the installation of the OSSEC server first.

  • yum install -y gcc inotify-tools bind-utils pcre-devel wget
  • wget -O ossec.tar.gz
  • tar xfvz ossec.tar.gz
  • cd ossec-hids*
  • ./
  • Edit /var/ossec/etc/ossec.conf to add :
  • /var/ossec/bin/ossec-control enable client-syslog
  • /var/ossec/bin/ossec-control start

Now let’s start setting up ELK stack

  • Now install java using: sudo yum install java-1.8.0-openjdk
  • Download logstash rpm file from
  • rpm -Uvh logstash-*.rpm
  • Add file in logstash directory: /etc/logstash/conf.d/OSSEC-logstash.conf with following content:
input {
# stdin{}
  udp {
     port => 5001
     type => "ossec"

filter {
  if [type] == "ossec" {
    grok {
      match => { "message" => "%{SYSLOGTIMESTAMP:syslog_timestamp} %{SYSLOGHOST:syslog_host} %{DATA:syslog_program}: Alert Level: %{NONNEGINT:Alert_Level}; Rule: %{NONNEGINT:Rule} - %{DATA:Description}; Location: %{DATA:Location}; (user: %{USER:User};%{SPACE})?(srcip: %{IP:Src_IP};%{SPACE})?(user: %{USER:User};%{SPACE})?(dstip: %{IP:Dst_IP};%{SPACE})?(src_port: %{NONNEGINT:Src_Port};%{SPACE})?(dst_port: %{NONNEGINT:Dst_Port};%{SPACE})?%{GREEDYDATA:Details}" }
      add_field => [ "ossec_server", "%{host}" ]
    mutate {
      remove_field => [ "message","syslog_timestamp", "syslog_program", "syslog_host", "syslog_message", "syslog_pid", "@version", "type", "host" ]

output {
  elasticsearch { hosts => ["localhost:9200"] }
  stdout { codec => rubydebug }
  • Now try restarting the logstash using following command: systemctl restart logstash
  • Or try this command is service not found: sudo /usr/share/logstash/bin/system-install /etc/logstash/startup.options systemd
  • Download Elasticsearch rpm file from
  • rpm -Uvh elasticsearch-*.rpm
  • Edit elasticsearch file in /etc/elasticsearch/elasticsearch.yml with following changes:
1. Change cluster name to ossec
2. Change the host ip address (
3. ossec-server-node-1
  • systemctl enable elasticsearch
  • systemctl start elasticsearch
  • Download Kibana rpm file from
  • rpm -Uvh kibana-*.rpm
  • Edit kibana file in /etc/kibana/kibana.yml with following changes:
1. Change elasticsearch information if needed. (elasticsearch.hosts: [""] or elasticsearch.url: "http://localhost:9200")

2. Change kibana ip address to (server.port: 5601, "")
  • systemctl enable kibana
  • systemctl start kibana
  • Try accessing you kibana dashboard at http://server-ip:5601 if not able to try opening specific port in iptables


Email me for help :

1 thought on “Getting OSSEC Server Logs into ELK stack”

Leave a Comment