peekjef72 / httpapi_exporter

generic http REST API exporter
MIT License
7 stars 1 forks source link
arubacx exporter hp3par httpapi json netscaler prometheus veeam

Prometheus HTTPAPI Exporter

This exporter wants to be a generic JSON REST API exporter. That's mean it can login, then makes requests to collect metrics and performs transformations on values and finally returns metrics in prometheus format.

Nothing is hard coded in the exporter. That why it is a generic exporter.

As examples 4 configurations for exporters are provided (see contribs):

Build

use promu tool

go install github.com/prometheus/promu@latest
go install github.com/peekjef72/passwd_encrypt@latest

$GOBIN/promu build

or simply make.

make

this will build the exporter and a tool to crypt/decrypt ciphertext with a shared passphrase.

Usage

usage: httpapi_exporter [<flags>]

Flags:
  -h, --[no-]help            Show context-sensitive help (also try --help-long and --help-man).
      --web.listen-address=":9321"
                             The address to listen on for HTTP requests.
      --web.telemetry-path="/metrics"
                             Path under which to expose collector's internal metrics.
  -c, --config.file="config/config.yml"
                             Exporter configuration file.
  -n, --[no-]dry-run         Only check exporter configuration file and exit.
  -t, --target=TARGET        In dry-run mode specify the target name, else ignored.
  -a, --auth.key=AUTH.KEY    In dry-run mode specify the auth_key to use, else ignored.
  -o, --collector=COLLECTOR  Specify the collector name restriction to collect, replace the collector_names set for each target.
      --log.level=info       Only log messages with the given severity or above. One of: [debug, info, warn, error]
      --log.format=logfmt    Output format of log messages. One of: [logfmt, json]
  -V, --[no-]version         Show application version.

Loging level

You can change the log.level online by sending a signal USR2 to the process. It will increase and cycle into levels each time a signal is received.

kill -USR2 pid

Usefull if something is wrong and you want to have detailled log only for a small interval.

You can also set the loglevel using API endpoint /loglevel

Reload

You can tell the exporter to reload its configuration by sending a signal HUP to the process or send a POST request to /reload endpoint.

Exporter configuration

Exporter requires configuration to works:

exporter http server

the exporter http server has a default landing page that permit to access

exporter metrics access

parameters to scrape a target:

examples:

  1. /metrics?target=mytarget scrapes the target mytarget without any parameter; It must be fully defined in the exporter configuration files; it has either no authentication or password is not encrypted.
  2. /metrics?auth_key=<cipherkey>&target=mytarget2 scrapes the target mytarget2 that is fully defined in the exporter configuration files, and has a password that is encrypted and can be decrypted with the cipherkey.
  3. /metrics?auth_key=<cipherkey>&target=<https://myhost.domain.name:port>&auth_name=<auth_name> define a dynamic target that is reachable at url https://myhost.domain.name:port, using the authentication parameters defined by <auth_name> and "default" model, then scrapes it. This target was not initially defined in the exporter configuration files, and only exists until the exporter is running.
  4. /metrics?auth_key=<cipherkey>&target=<https://myhost.domain.name:port>&auth_name=<auth_name>&model=mytarget same than previous example but the dynamic target creation use "mytarget" model instead of default.

Authentication

Most of the time the access to a http api requires an authentication. It is the case for the 3 contribs (hp3par, veeam, netscaler). The exporter allows you 2 modes:

The auth parameters are :

The user, password and token values can be raw strings or retrive the values from environment variables. To use env var the value must be prefixed by "$env:" followed by the name of the variable.

  # use this auth_config to authenticate via env vars
  default:
    mode: script
    user: $env:VEEAM_EXPORTER_USER
    password: $env:VEEAM_EXPORTER_PASSWD

password encryption

If you don't want to write the users' password in clear text in config file (targets files on the exporter), you can encrypt them with a shared password.

How it works:

(still incomplete)

Go template is used to manipulate data. So templates inherits from go functions and sprig v3 functions. Because the exporter uses most of the time data of type "any (interface{})" some of the sprig functions failed. Here is the list of exporter functions:

name usage e.g.
exporterDecryptPass
exporterGet [varmap] [keyname] get the keyname from the map. Like sprig/get function but accepts data of type map[any]any exporterGet .svclb .svc
exporterSet
exporterKeys
exporterValues
exporterToRawJson
lookupAddr [varstring] obtain hostname from string representing and ip address ; like sprig/getHostByName but for string ip lookupAddr .node.ipaddress
convertToBytes
getHeader [varmap]
LEN [var] obtain the len of the var. works like sprig/len but accepts data of type any.

boolean checks

name usage e.g.
EQ [var1] [var2] check equality for 2 variables; accepts any type of data; meaning that the second will be converted to the type of the first EQ .val "2"
NE [var1] [var2] not equal NE 2 .val
GE [var1] [var2] greater equal
GT [var1] [var2] greater than
LE [var1] [var2] less equal
LT [var1] [var2] less than
exists [var1] return boolean if variable exists exists .config.cluster.node
exporterHasKey [var] [key] check if variable is a map and has a key exporterHasKey .config "cluster"