Stephane Barbarie | 3eab2bb | 2017-04-24 15:04:23 -0400 | [diff] [blame] | 1 | ## ------------------------------------------ |
| 2 | ## Retrieve messages from Voltha alarm topic |
| 3 | ## ------------------------------------------ |
| 4 | |
| 5 | input { |
| 6 | kafka { |
| 7 | bootstrap_servers => "10.100.198.220:9092" |
| 8 | topics => ["voltha.alarms"] |
| 9 | tags => [ "alarm" ] |
| 10 | type => "voltha_alarms" |
| 11 | } |
| 12 | } |
| 13 | |
| 14 | ## ------------------------------------------ |
| 15 | ## The message field is a JSON block. |
| 16 | ## Break it down in multiple fields |
| 17 | ## for easy extraction |
| 18 | ## ------------------------------------------ |
| 19 | |
| 20 | filter { |
| 21 | json{ |
| 22 | source => "message" |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | ## ------------------------------------------ |
| 27 | ## Intercept alarm messages and manipulate |
| 28 | ## the content prior to injection in OpenNMS |
| 29 | ## ------------------------------------------ |
| 30 | |
| 31 | filter { |
| 32 | if "alarm" in [tags] { |
| 33 | mutate { |
| 34 | add_field => { "[@metadata][alarm_id]" => "%{id}" } |
| 35 | add_field => { "[@metadata][resource_id]" => "%{resource_id}" } |
| 36 | add_field => { "[@metadata][description]" => "%{description}" } |
| 37 | add_field => { "[@metadata][type]" => "%{type}" } |
| 38 | add_field => { "[@metadata][category]" => "%{category}" } |
| 39 | add_field => { "[@metadata][state]" => "%{state}" } |
| 40 | add_field => { "[@metadata][raised_time]" => "%{raised_ts}" } |
| 41 | add_field => { "[@metadata][reported_time]" => "%{reported_ts}" } |
| 42 | add_field => { "[@metadata][changed_time]" => "%{changed_ts}" } |
| 43 | add_field => { "[@metadata][context]" => "%{context}" } |
| 44 | add_field => { "[@metadata][service]" => "voltha" } |
| 45 | add_field => { "[@metadata][interface]" => "localhost" } |
| 46 | add_tag => "opennms" |
| 47 | } |
| 48 | |
| 49 | if [state] == "RAISED" { |
| 50 | mutate { |
| 51 | add_field => { "[@metadata][uei]" => "uei.opennms.org/vendor/voltha/alarmRaised" } |
| 52 | add_field => { "[@metadata][severity]" => "%{severity}" } |
| 53 | } |
| 54 | } else if [state] == "CLEARED" { |
| 55 | mutate { |
| 56 | add_field => { "[@metadata][uei]" => "uei.opennms.org/vendor/voltha/alarmCleared" } |
| 57 | add_field => { "[@metadata][severity]" => "Normal" } |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | ## ------------------------------------------ |
| 64 | ## View incoming messages (for debugging) |
| 65 | ## ------------------------------------------ |
| 66 | |
| 67 | output { |
| 68 | stdout { |
| 69 | codec => rubydebug { metadata => true } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | ## ------------------------------------------ |
| 74 | ## Forward alarm messages to OpenNMS |
| 75 | ## ------------------------------------------ |
| 76 | |
| 77 | output { |
| 78 | if "opennms" in [tags] { |
| 79 | opennms { |
| 80 | opennms_server_hosts => { |
| 81 | "10.100.198.220" => 5817 |
| 82 | } |
| 83 | |
| 84 | opennms_event_timezone => "utc" |
| 85 | opennms_event_service => "[@metadata][service]" |
| 86 | opennms_event_nodeid => 0 |
| 87 | opennms_event_interface => "[@metadata][interface]" |
| 88 | opennms_event_uei => "[@metadata][uei]" |
| 89 | opennms_event_severity => "[@metadata][severity]" |
| 90 | opennms_event_description => "[@metadata][description]" |
| 91 | opennms_event_logmsg => "logmsg" |
| 92 | |
| 93 | opennms_event_parms => { |
| 94 | "AlarmId" => "[@metadata][alarm_id]" |
| 95 | "ResourceId" => "[@metadata][resource_id]" |
| 96 | "Description" => "[@metadata][description]" |
| 97 | "Type" => "[@metadata][type]" |
| 98 | "Category" => "[@metadata][category]" |
| 99 | "State" => "[@metadata][state]" |
| 100 | "Severity" => "[@metadata][severity]" |
| 101 | "RaisedTime" => "[@metadata][raised_time]" |
| 102 | "ReportedTime" => "[@metadata][reported_time]" |
| 103 | "ChangedTime" => "[@metadata][changed_time]" |
| 104 | "Context" => "[@metadata][context]" |
| 105 | } |
| 106 | |
| 107 | opennms_event_parms_order => [ "AlarmId", "ResourceId", "Description", "Type", "Category", "State", "Severity", "RaisedTime", "ReportedTime", "ChangedTime", "Context" ] |
| 108 | } |
| 109 | } |
| 110 | } |