]> xn--ix-yja.es Git - alex.git/commitdiff
Parse nagios.log and send notifications to clickhouse.h1
authoralex <alex@pdp7.net>
Mon, 13 Nov 2023 22:32:19 +0000 (23:32 +0100)
committeralex <alex@pdp7.net>
Mon, 13 Nov 2023 22:32:19 +0000 (23:32 +0100)
personal_infra/puppet/site/nagios.h1.int.pdp7.net.pp

index 262b8026eaa6404cf87fda2636ae1289f66240f0..4010d3c44d485274ef3e1bdf730452937dbcd0a1 100644 (file)
@@ -17,4 +17,48 @@ node 'nagios.h1.int.pdp7.net' {
   }
 
   package {'nagios-plugins-pgsql':}
+
+  class {'otel':
+    version => '0.88.0',
+  }
+
+  # TODO: add otelcol-contrib user to nagios group
+  file {'/etc/otelcol-contrib/config.yaml':
+    content => @("EOT")
+      exporters:
+        otlp:
+          endpoint: clickhouse.h1.int.pdp7.net:4317
+          tls:
+            insecure: true
+
+      receivers:
+        filelog:
+          include: [ /var/log/nagios/nagios.log ]
+          operators:
+            - type: regex_parser
+              regex: '^\[(?P<time>\d+)\] (?P<log>.*)$'
+              timestamp:
+                parse_from: attributes.time
+                layout_type: epoch
+                layout: s
+
+      processors:
+        transform:
+          log_statements:
+            - context: log
+              statements:
+                - merge_maps(attributes, ExtractPatterns(attributes["log"], "^(?P<type>SERVICE NOTIFICATION):[ ](?P<contact>[^;]*);(?P<host>[^;]*);(?P<service>[^;]*);(?P<status>[^;]*);(?P<command>[^;]*);(?P<check_status_line>.*)$"), "insert") where IsMatch(attributes["log"], "^SERVICE NOTIFICATION:")
+                - merge_maps(attributes, ExtractPatterns(attributes["log"], "^(?P<type>HOST NOTIFICATION):[ ](?P<contact>[^;]*);(?P<host>[^;]*);(?P<status>[^;]*);(?P<command>[^;]*);(?P<check_status_line>.*)$"), "insert") where IsMatch(attributes["log"], "^HOST NOTIFICATION:")
+
+      service:
+        pipelines:
+          logs:
+            receivers: [filelog]
+            processors: [transform]
+            exporters: [otlp]
+      | EOT
+    ,
+    require => Package['otelcol-contrib'],
+    notify => Service['otelcol-contrib'],
+  }
 }