mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-12-28 14:22:50 +03:00
Merge pull request #81857 from mmilata/prometheus-mikrotik-exporter
nixos/prometheus-mikrotik-exporter: init
This commit is contained in:
commit
3cd57cfe2c
@ -29,6 +29,7 @@ let
|
||||
"fritzbox"
|
||||
"json"
|
||||
"mail"
|
||||
"mikrotik"
|
||||
"minio"
|
||||
"nextcloud"
|
||||
"nginx"
|
||||
@ -204,6 +205,14 @@ in
|
||||
Please ensure you have either `services.prometheus.exporters.snmp.configuration'
|
||||
or `services.prometheus.exporters.snmp.configurationPath' set!
|
||||
'';
|
||||
} {
|
||||
assertion = cfg.mikrotik.enable -> (
|
||||
(cfg.mikrotik.configFile == null) != (cfg.mikrotik.configuration == null)
|
||||
);
|
||||
message = ''
|
||||
Please specify either `services.prometheus.exporters.mikrotik.configuration'
|
||||
or `services.prometheus.exporters.mikrotik.configFile'.
|
||||
'';
|
||||
} {
|
||||
assertion = cfg.mail.enable -> (
|
||||
(cfg.mail.configFile == null) != (cfg.mail.configuration == null)
|
||||
|
@ -0,0 +1,66 @@
|
||||
{ config, lib, pkgs, options }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.services.prometheus.exporters.mikrotik;
|
||||
in
|
||||
{
|
||||
port = 9436;
|
||||
extraOpts = {
|
||||
configFile = mkOption {
|
||||
type = types.nullOr types.path;
|
||||
default = null;
|
||||
description = ''
|
||||
Path to a mikrotik exporter configuration file. Mutually exclusive with
|
||||
<option>configuration</option> option.
|
||||
'';
|
||||
example = literalExample "./mikrotik.yml";
|
||||
};
|
||||
|
||||
configuration = mkOption {
|
||||
type = types.nullOr types.attrs;
|
||||
default = null;
|
||||
description = ''
|
||||
Mikrotik exporter configuration as nix attribute set. Mutually exclusive with
|
||||
<option>configFile</option> option.
|
||||
|
||||
See <link xlink:href="https://github.com/nshttpd/mikrotik-exporter/blob/master/README.md"/>
|
||||
for the description of the configuration file format.
|
||||
'';
|
||||
example = literalExample ''
|
||||
{
|
||||
devices = [
|
||||
{
|
||||
name = "my_router";
|
||||
address = "10.10.0.1";
|
||||
user = "prometheus";
|
||||
password = "changeme";
|
||||
}
|
||||
];
|
||||
features = {
|
||||
bgp = true;
|
||||
dhcp = true;
|
||||
routes = true;
|
||||
optics = true;
|
||||
};
|
||||
}
|
||||
'';
|
||||
};
|
||||
};
|
||||
serviceOpts = let
|
||||
configFile = if cfg.configFile != null
|
||||
then cfg.configFile
|
||||
else "${pkgs.writeText "mikrotik-exporter.yml" (builtins.toJSON cfg.configuration)}";
|
||||
in {
|
||||
serviceConfig = {
|
||||
# -port is misleading name, it actually accepts address too
|
||||
ExecStart = ''
|
||||
${pkgs.prometheus-mikrotik-exporter}/bin/mikrotik-exporter \
|
||||
-config-file=${escapeShellArg configFile} \
|
||||
-port=${cfg.listenAddress}:${toString cfg.port} \
|
||||
${concatStringsSep " \\\n " cfg.extraFlags}
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
@ -245,6 +245,46 @@ let
|
||||
'';
|
||||
};
|
||||
|
||||
mikrotik = {
|
||||
exporterConfig = {
|
||||
enable = true;
|
||||
extraFlags = [ "-timeout=1s" ];
|
||||
configuration = {
|
||||
devices = [
|
||||
{
|
||||
name = "router";
|
||||
address = "192.168.42.48";
|
||||
user = "prometheus";
|
||||
password = "shh";
|
||||
}
|
||||
];
|
||||
features = {
|
||||
bgp = true;
|
||||
dhcp = true;
|
||||
dhcpl = true;
|
||||
dhcpv6 = true;
|
||||
health = true;
|
||||
routes = true;
|
||||
poe = true;
|
||||
pools = true;
|
||||
optics = true;
|
||||
w60g = true;
|
||||
wlansta = true;
|
||||
wlanif = true;
|
||||
monitor = true;
|
||||
ipsec = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
exporterTest = ''
|
||||
wait_for_unit("prometheus-mikrotik-exporter.service")
|
||||
wait_for_open_port(9436)
|
||||
succeed(
|
||||
"curl -sSf http://localhost:9436/metrics | grep -q 'mikrotik_scrape_collector_success{device=\"router\"} 0'"
|
||||
)
|
||||
'';
|
||||
};
|
||||
|
||||
nextcloud = {
|
||||
exporterConfig = {
|
||||
enable = true;
|
||||
|
22
pkgs/servers/monitoring/prometheus/mikrotik-exporter.nix
Normal file
22
pkgs/servers/monitoring/prometheus/mikrotik-exporter.nix
Normal file
@ -0,0 +1,22 @@
|
||||
{ stdenv, buildGoModule, fetchFromGitHub }:
|
||||
|
||||
buildGoModule rec {
|
||||
pname = "mikrotik-exporter-unstable";
|
||||
version = "2020-02-10";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "nshttpd";
|
||||
repo = "mikrotik-exporter";
|
||||
sha256 = "193zh06rqp9ybsnkxwmv7l4p2h2xisw4f01jjirshsb784j44bh6";
|
||||
rev = "3b33400d24abcfdc07dc31c15ca5ba7b82de444f";
|
||||
};
|
||||
|
||||
modSha256 = "1cqjn6j3dfq51ssjx0qrajprlac1h0lb1r4af44lfpigzmrfyi07";
|
||||
|
||||
meta = with stdenv.lib; {
|
||||
inherit (src.meta) homepage;
|
||||
description = "Prometheus MikroTik device(s) exporter";
|
||||
license = licenses.bsd3;
|
||||
maintainers = with maintainers; [ mmilata ];
|
||||
};
|
||||
}
|
@ -15797,6 +15797,7 @@ in
|
||||
prometheus-json-exporter = callPackage ../servers/monitoring/prometheus/json-exporter.nix { };
|
||||
prometheus-mail-exporter = callPackage ../servers/monitoring/prometheus/mail-exporter.nix { };
|
||||
prometheus-mesos-exporter = callPackage ../servers/monitoring/prometheus/mesos-exporter.nix { };
|
||||
prometheus-mikrotik-exporter = callPackage ../servers/monitoring/prometheus/mikrotik-exporter.nix { };
|
||||
prometheus-minio-exporter = callPackage ../servers/monitoring/prometheus/minio-exporter { };
|
||||
prometheus-mysqld-exporter = callPackage ../servers/monitoring/prometheus/mysqld-exporter.nix { };
|
||||
prometheus-nextcloud-exporter = callPackage ../servers/monitoring/prometheus/nextcloud-exporter.nix { };
|
||||
|
Loading…
Reference in New Issue
Block a user