Skip to content

Commit 8a1cbf5

Browse files
committed
Update logstash parsing contribution
1 parent 698d3da commit 8a1cbf5

File tree

3 files changed

+118
-92
lines changed

3 files changed

+118
-92
lines changed

contrib/logstash/README.rst

+12-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Alignak Logstash
33
================
44

5-
Alignak monitoring log is easily parsable thanks to logstash to store all the monitoring events into an Elasticsearch database. Logstash is a powerful and easy to use log parser... and Kibana alllows to easily build dashboards from the data collected ;)
5+
Alignak monitoring events log is easily parsable thanks to logstash to store all the monitoring events into an Elasticsearch database or any other...). Logstash is a powerful and easy to use log parser... and Kibana allows to easily build dashboards from the data collected ;)
66

77

88
Installation
@@ -15,12 +15,21 @@ A `logstash.conf` example file is available in the same directory as this doc fi
1515
Configuration
1616
-------------
1717

18-
Copy the `logstash.conf` in the logstash configuration directory (eg. */usr/local/etc/logstash*) and copy the *patterns* directory of this repository in the same place.
18+
Copy the `logstash.conf` in the logstash configuration directory (eg. */etc/logstash*) and copy the *patterns* directory of this repository in the same place.
1919

2020
Update the `logstash.conf` according to your configuration. Some important updates:
2121
- the date inserted in each log is formatted according to the logger configuration. Often it is an ISO date yyyy-mm-dd hh:mm:ss but you may have set this date as a unix timestamp. Update the patterns and the `logstash.conf` accordingly
2222
- the elasticsearch URL must be updated to connect your own ES cluster
2323

24+
Using an output plugin for MongoDB allows to get Alignak events log in a MongoDB collection::
25+
26+
# Install the output plugin for MongoDB
27+
$ sudo /usr/share/logstash/bin/logstash-plugin install logstash-output-mongodb
28+
Validating logstash-output-mongodb
29+
Installing logstash-output-mongodb
30+
Installation successful
31+
32+
2433
Collected information
2534
---------------------
2635

@@ -37,3 +46,4 @@ The logstash parser is able to analyse the Alignak daemons log files. Extracted
3746
Monitoring log
3847
~~~~~~~~~~~~~~
3948

49+
All the monitoring events are extracted from the monitoring events log and pushed to the output plugins defined in the logstash.conf file: elasticsearch and / or mongodb. Default is to push to elasticsearch; you can uncomment to push the parsed log to a Mongo database.

contrib/logstash/logstash.conf

+51-37
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
input {
22
# Monitoring events log
33
file {
4-
type => "alignak_monitoring_log"
4+
type => "alignak_events_log"
55
path => [
6-
"/usr/local/var/log/alignak/monitoring-log/*"
6+
# "/usr/local/var/log/alignak/monitoring-log/*"
7+
"/tmp/var/log/alignak/alignak-events.log"
78
]
8-
tags => [ "alignak-monitoring" ]
9+
tags => [ "alignak-events" ]
910
start_position => "beginning"
10-
sincedb_path => "/var/db/logstash/since_alignak_monitoring"
11+
sincedb_path => "/var/run/logstash/since_alignak_events"
1112
codec => multiline {
12-
patterns_dir => ["/usr/local/etc/logstash/patterns"]
13+
patterns_dir => ["/etc/logstash/patterns"]
1314
pattern => "^%{ALIGNAK_TIME}"
1415
negate => true
1516
what => "previous"
@@ -24,9 +25,9 @@ input {
2425
]
2526
tags => [ "alignak-daemon" ]
2627
start_position => "beginning"
27-
sincedb_path => "/var/db/logstash/since_alignak_daemon"
28+
sincedb_path => "/var/run/logstash/since_alignak_daemon"
2829
codec => multiline {
29-
patterns_dir => ["/usr/local/etc/logstash/patterns"]
30+
patterns_dir => ["/etc/logstash/patterns"]
3031
pattern => "^%{ALIGNAK_DAEMON_TIME}"
3132
negate => true
3233
what => "previous"
@@ -36,11 +37,19 @@ input {
3637

3738
filter {
3839
# Monitoring events log
39-
if [type] == "alignak_monitoring_log" {
40+
if [type] == "alignak_events_log" {
4041
grok {
41-
patterns_dir => ["/usr/local/etc/logstash/patterns"]
42+
patterns_dir => ["/etc/logstash/patterns"]
4243
match => { "message" => "%{ALIGNAK_LOG}" }
4344
}
45+
date {
46+
match => [ "[alignak][timestamp]", "yyyy-MM-dd HH:mm:ss" ]
47+
target => "@timestamp"
48+
}
49+
date {
50+
match => [ "[alignak][timestamp]", "yyyy-MM-dd HH:mm:ss" ]
51+
target => "[alignak][timestamp]"
52+
}
4453
csv {
4554
source => "[alignak][check_result]"
4655
separator => ";"
@@ -61,10 +70,6 @@ filter {
6170
columns => [ "dummy", "[alignak][host_name]", "[alignak][service]", "[alignak][state_id]", "[alignak][check_result]" ]
6271
}
6372
}
64-
date {
65-
match => [ "[alignak][timestamp]", "yyyy-MM-dd HH:mm:ss" ]
66-
target => "[alignak][timestamp]"
67-
}
6873
if [alignak][ext_cmd_timestamp] {
6974
date {
7075
match => [ "[alignak][ext_cmd_timestamp]", "UNIX" ]
@@ -77,22 +82,17 @@ filter {
7782
ruby {
7883
code => "event.set('@timestamp', event.get('[alignak][ext_cmd_timestamp]'));"
7984
}
80-
#mutate {
81-
# update => { "@timestamp" => "[alignak][ext_cmd_timestamp]" }
82-
#}
83-
}
84-
} else {
85-
date {
86-
match => [ "[alignak][timestamp]", "yyyy-MM-dd HH:mm:ss" ]
87-
target => "@timestamp"
85+
mutate {
86+
update => { "@timestamp" => "[alignak][ext_cmd_timestamp]" }
87+
}
8888
}
8989
}
9090
}
9191

9292
# Daemons log
9393
if [type] == "alignak_daemon" {
9494
grok {
95-
patterns_dir => ["/usr/local/etc/logstash/patterns"]
95+
patterns_dir => ["/etc/logstash/patterns"]
9696
match => { "message" => "%{ALIGNAK_DAEMON_LOG}" }
9797
}
9898
date {
@@ -107,21 +107,35 @@ filter {
107107

108108
output {
109109
# Emit events to stdout for easy debugging of what is going through logstash.
110-
# stdout { debug => "true" }
111-
# stdout { codec => rubydebug }
110+
stdout { codec => rubydebug }
111+
112+
# Alignak daemons log
113+
# if [type] == "alignak-daemon" {
114+
# This will use elasticsearch to store your logs.
115+
# elasticsearch {
116+
# hosts => [ "es1:9200" ]
117+
# index => "logstash-alignak-daemon-%{+YYYY.MM.dd}"
118+
# }
119+
# }
112120

113-
if [type] == "alignak-daemon" {
114-
# This will use elasticsearch to store your logs.
115-
elasticsearch {
116-
hosts => [ "es1:9200" ]
117-
index => "logstash-alignak-daemon-%{+YYYY.MM.dd}"
118-
}
119-
}
121+
# Alignak events log
122+
if [type] == "alignak_events_log" {
123+
elasticsearch {
124+
hosts => ["es1:9200"]
125+
index => "logstash-alignak-events-%{+YYYY.MM.dd}"
126+
}
120127

121-
if [type] == "alignak-monitoring" {
122-
elasticsearch {
123-
hosts => ["es1:9200"]
124-
index => "logstash-alignak-monitoring-%{+YYYY.MM.dd}"
125-
}
126-
}
128+
# mongodb {
129+
# id => "alignak_mongodb_plugin_id"
130+
# collection => "alignak_events"
131+
# database => "alignak"
132+
# uri => "mongodb://localhost:27017"
133+
# # bulk => "true"
134+
# # bulk_interval => 10
135+
# # bulk_size => 50
136+
# # generateId => "true"
137+
# # isodate => "true"
138+
# # codec => "json"
139+
# }
140+
}
127141
}

0 commit comments

Comments
 (0)