Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: prometheus-exporter_clamav #562

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/severity.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
- [organization_usage](#organization_usage)
- [otel-collector_kubernetes-common](#otel-collector_kubernetes-common)
- [prometheus-exporter_active-directory](#prometheus-exporter_active-directory)
- [prometheus-exporter_clamav](#prometheus-exporter_clamav)
- [prometheus-exporter_docker-state](#prometheus-exporter_docker-state)
- [prometheus-exporter_kong](#prometheus-exporter_kong)
- [prometheus-exporter_oracledb](#prometheus-exporter_oracledb)
Expand Down Expand Up @@ -874,6 +875,13 @@
|Active-directory active directory services|X|-|-|-|-|


## prometheus-exporter_clamav

|Detector|Critical|Major|Minor|Warning|Info|
|---|---|---|---|---|---|
|Clamav heartbeat|X|-|-|-|-|


## prometheus-exporter_docker-state

|Detector|Critical|Major|Minor|Warning|Info|
Expand Down
113 changes: 113 additions & 0 deletions modules/prometheus-exporter_clamav/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# CLAMAV SignalFx detectors

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
:link: **Contents**

- [How to use this module?](#how-to-use-this-module)
- [What are the available detectors in this module?](#what-are-the-available-detectors-in-this-module)
- [How to collect required metrics?](#how-to-collect-required-metrics)
- [Metrics](#metrics)
- [Related documentation](#related-documentation)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## How to use this module?

This directory defines a [Terraform](https://www.terraform.io/)
[module](https://www.terraform.io/language/modules/syntax) you can use in your
existing [stack](https://github.com/claranet/terraform-signalfx-detectors/wiki/Getting-started#stack) by adding a
`module` configuration and setting its `source` parameter to URL of this folder:

```hcl
module "signalfx-detectors-prometheus-exporter-clamav" {
source = "github.com/hugueslepesant/terraform-signalfx-detectors.git//modules/prometheus-exporter_clamav?ref={revision}"

environment = var.environment
notifications = local.notifications
}
```

Note the following parameters:

* `source`: Use this parameter to specify the URL of the module. The double slash (`//`) is intentional and required.
Terraform uses it to specify subfolders within a Git repo (see [module
sources](https://www.terraform.io/language/modules/sources)). The `ref` parameter specifies a specific Git tag in
this repository. It is recommended to use the latest "pinned" version in place of `{revision}`. Avoid using a branch
like `master` except for testing purpose. Note that every modules in this repository are available on the Terraform
[registry](https://registry.terraform.io/modules/claranet/detectors/signalfx) and we recommend using it as source
instead of `git` which is more flexible but less future-proof.

* `environment`: Use this parameter to specify the
[environment](https://github.com/claranet/terraform-signalfx-detectors/wiki/Getting-started#environment) used by this
instance of the module.
Its value will be added to the `prefixes` list at the start of the [detector
name](https://github.com/claranet/terraform-signalfx-detectors/wiki/Templating#example).
In general, it will also be used in the `filtering` internal sub-module to [apply
filters](https://github.com/claranet/terraform-signalfx-detectors/wiki/Guidance#filtering) based on our default
[tagging convention](https://github.com/claranet/terraform-signalfx-detectors/wiki/Tagging-convention) by default.

* `notifications`: Use this parameter to define where alerts should be sent depending on their severity. It consists
of a Terraform [object](https://www.terraform.io/language/expressions/type-constraints#object) where each key represents an available
[detector rule severity](https://docs.splunk.com/observability/alerts-detectors-notifications/create-detectors-for-alerts.html#severity)
and its value is a list of recipients. Every recipients must respect the [detector notification
format](https://registry.terraform.io/providers/splunk-terraform/signalfx/latest/docs/resources/detector#notification-format).
Check the [notification binding](https://github.com/claranet/terraform-signalfx-detectors/wiki/Notifications-binding)
documentation to understand the recommended role of each severity.

These 3 parameters along with all variables defined in [common-variables.tf](common-variables.tf) are common to all
[modules](../) in this repository. Other variables, specific to this module, are available in
[variables-gen.tf](variables-gen.tf).
In general, the default configuration "works" but all of these Terraform
[variables](https://www.terraform.io/language/values/variables) make it possible to
customize the detectors behavior to better fit your needs.

Most of them represent usual tips and rules detailed in the
[guidance](https://github.com/claranet/terraform-signalfx-detectors/wiki/Guidance) documentation and listed in the
common [variables](https://github.com/claranet/terraform-signalfx-detectors/wiki/Variables) dedicated documentation.

Feel free to explore the [wiki](https://github.com/claranet/terraform-signalfx-detectors/wiki) for more information about
general usage of this repository.

## What are the available detectors in this module?

This module creates the following SignalFx detectors which could contain one or multiple alerting rules:

|Detector|Critical|Major|Minor|Warning|Info|
|---|---|---|---|---|---|
|Clamav heartbeat|X|-|-|-|-|

## How to collect required metrics?

This module deploys detectors using metrics reported by the
scraping of a server following the [OpenMetrics convention](https://openmetrics.io/) based on and compatible with [the Prometheus
exposition format](https://github.com/prometheus/docs/blob/main/content/docs/instrumenting/exposition_formats.md#openmetrics-text-format).

They are generally called `Prometheus Exporters` which can be fetched by both the [SignalFx Smart Agent](https://github.com/signalfx/signalfx-agent)
thanks to its [prometheus exporter monitor](https://github.com/signalfx/signalfx-agent/blob/main/docs/monitors/prometheus-exporter.md) and the
[OpenTelemetry Collector](https://github.com/signalfx/splunk-otel-collector) using its [prometheus
receiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/prometheusreceiver) or its derivatives.

These exporters could be embedded directly in the tool you want to monitor (e.g. nginx ingress) or must be installed next to it as
a separate program configured to connect, create metrics and expose them as server.


Check the [Related documentation](#related-documentation) section for more detailed and specific information about this module dependencies.



### Metrics


Here is the list of required metrics for detectors in this module.

* `clamav_up`




## Related documentation

* [Terraform SignalFx provider](https://registry.terraform.io/providers/splunk-terraform/signalfx/latest/docs)
* [Terraform SignalFx detector](https://registry.terraform.io/providers/splunk-terraform/signalfx/latest/docs/resources/detector)
* [Splunk Observability integrations](https://docs.splunk.com/Observability/gdi/get-data-in/integrations.html)
1 change: 1 addition & 0 deletions modules/prometheus-exporter_clamav/common-filters.tf
1 change: 1 addition & 0 deletions modules/prometheus-exporter_clamav/common-locals.tf
1 change: 1 addition & 0 deletions modules/prometheus-exporter_clamav/common-modules.tf
1 change: 1 addition & 0 deletions modules/prometheus-exporter_clamav/common-variables.tf
1 change: 1 addition & 0 deletions modules/prometheus-exporter_clamav/common-versions.tf
13 changes: 13 additions & 0 deletions modules/prometheus-exporter_clamav/conf/00-heartbeat.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Example
module: clamav
name: heartbeat

transformation: false
aggregation: true
exclude_not_running_vm: true

signals:
signal:
metric: "clamav_up"
rules:
critical:
3 changes: 3 additions & 0 deletions modules/prometheus-exporter_clamav/conf/readme.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
documentations:

source_doc:
28 changes: 28 additions & 0 deletions modules/prometheus-exporter_clamav/detectors-gen.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
resource "signalfx_detector" "heartbeat" {
name = format("%s %s", local.detector_name_prefix, "Clamav heartbeat")

authorized_writer_teams = var.authorized_writer_teams
teams = try(coalescelist(var.teams, var.authorized_writer_teams), null)
tags = compact(concat(local.common_tags, local.tags, var.extra_tags))

program_text = <<-EOF
from signalfx.detectors.not_reporting import not_reporting
signal = data('clamav_up', filter=%{if var.heartbeat_exclude_not_running_vm}${local.not_running_vm_filters} and %{endif}${module.filtering.signalflow})${var.heartbeat_aggregation_function}.publish('signal')
not_reporting.detector(stream=signal, resource_identifier=None, duration='${var.heartbeat_timeframe}', auto_resolve_after='${local.heartbeat_auto_resolve_after}').publish('CRIT')
EOF

rule {
description = "has not reported in ${var.heartbeat_timeframe}"
severity = "Critical"
detect_label = "CRIT"
disabled = coalesce(var.heartbeat_disabled, var.detectors_disabled)
notifications = try(coalescelist(lookup(var.heartbeat_notifications, "critical", []), var.notifications.critical), null)
runbook_url = try(coalesce(var.heartbeat_runbook_url, var.runbook_url), "")
tip = var.heartbeat_tip
parameterized_subject = var.message_subject == "" ? local.rule_subject_novalue : var.message_subject
parameterized_body = var.message_body == "" ? local.rule_body : var.message_body
}

max_delay = var.heartbeat_max_delay
}

5 changes: 5 additions & 0 deletions modules/prometheus-exporter_clamav/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
output "heartbeat" {
description = "Detector resource for heartbeat"
value = signalfx_detector.heartbeat
}

4 changes: 4 additions & 0 deletions modules/prometheus-exporter_clamav/tags.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
locals {
tags = ["prometheus-exporter", "clamav"]
}

50 changes: 50 additions & 0 deletions modules/prometheus-exporter_clamav/variables-gen.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# heartbeat detector

variable "heartbeat_notifications" {
description = "Notification recipients list per severity overridden for heartbeat detector"
type = map(list(string))
default = {}
}

variable "heartbeat_aggregation_function" {
description = "Aggregation function and group by for heartbeat detector (i.e. \".mean(by=['host'])\")"
type = string
default = ""
}

variable "heartbeat_max_delay" {
description = "Enforce max delay for heartbeat detector (use \"0\" or \"null\" for \"Auto\")"
type = number
default = null
}

variable "heartbeat_tip" {
description = "Suggested first course of action or any note useful for incident handling"
type = string
default = ""
}

variable "heartbeat_runbook_url" {
description = "URL like SignalFx dashboard or wiki page which can help to troubleshoot the incident cause"
type = string
default = ""
}

variable "heartbeat_disabled" {
description = "Disable all alerting rules for heartbeat detector"
type = bool
default = null
}

variable "heartbeat_exclude_not_running_vm" {
description = "Don’t send alerts if associated VM is stopped or stopping (metadata provided by cloud provider integration). Can be useful for ephemeral infrastructure (such as auto scaling groups) as VM will be stopped and started regularly. Note that timeframe must be at least 25 minutes for the metadata to be available to the detector."
type = bool
default = true
}

variable "heartbeat_timeframe" {
description = "Timeframe for heartbeat detector (i.e. \"25m\"). Must be at least \"25m\" if \"heartbeat_exclude_not_running_vm\" is true"
type = string
default = "25m"
}

Loading