baxic-snmp-exporter.0.1.0.linux-noarch/0000755002342000234200000000000014043323076016762 5ustar baxicbaxicbaxic-snmp-exporter.0.1.0.linux-noarch/RELEASE-NOTES0000644002342000234200000000004414043076357020660 0ustar baxicbaxic0.1.0 - Initial version released. baxic-snmp-exporter.0.1.0.linux-noarch/AUTHOR0000644002342000234200000000005114043076357017712 0ustar baxicbaxicLukas Baxa alias Baxic baxic-snmp-exporter.0.1.0.linux-noarch/baxic-snmp-exporter.conf0000644002342000234200000000027414042751637023552 0ustar baxicbaxic SNMP[0]='baxic_server:memory_total:1.3.6.1.4.1.2021.4.5.0' SNMP[1]='baxic_server:memory_free:1.3.6.1.4.1.2021.4.6.0' SNMP[10]='baxic_thermometer:temperature:0.1.3.6.1.4.1.21287.16.1.0' baxic-snmp-exporter.0.1.0.linux-noarch/baxic-snmp-exporter.service0000644002342000234200000000047314043076521024257 0ustar baxicbaxic[Unit] Description=Baxic SNMP Exporter Service After=network.target iptables.service firewalld.service ip6tables.service ipset.service [Service] Type=simple ExecStart=/opt/prometheus-apps/baxic-snmp-exporter/baxic-snmp-exporter.sh User=nobody Group=nogroup Restart=on-failure [Install] WantedBy=multi-user.target baxic-snmp-exporter.0.1.0.linux-noarch/baxic-snmp-exporter.sh0000755002342000234200000000332314042751550023232 0ustar baxicbaxic#!/bin/bash PROGNAME='baxic-snmp-exporter.sh' CONFFILE="/opt/prometheus-apps/${PROGNAME%.sh}/${PROGNAME%.sh}.conf" export PROGNAME CONFFILE # read_config_file # read configuration file read_config_file() { unset SNMP if [[ ! -f "$CONFFILE" || ! -r "$CONFFILE" ]]; then echo "$PROGNAME: configuration file '$CONFFILE' not found" exit 2 fi . "$CONFFILE" } read_config_file # get_metrics # get all metrics for the module and target specified in the HTTP GET header get_metrics() { local httpget module target local snmpconf modconf metric oid value local metrics metrics_len read httpget module="$(echo "$httpget" | sed -rn 's#^.*[&?]module=([^ &]*)(&[^ ]*)?.*[[:blank:]]+HTTP.*$#\1#p')" target="$(echo "$httpget" | sed -rn 's#^.*[&?]target=([^ &]*)(&[^ ]*)?.*[[:blank:]]+HTTP.*$#\1#p')" [[ -z "$module" || -z "$target" ]] && continue metrics="$(for snmpconf in "${SNMP[@]}"; do modconf="$(echo "$snmpconf" | cut -d: -f1)" metric="$(echo "$snmpconf" | cut -d: -f2)" oid="$(echo "$snmpconf" | cut -d: -f3)" [[ "$modconf" != "$module" ]] && continue value="$(snmpwalk -v 1 -c public "$target" "$oid" | sed -rn 's#[^:]*:[[:blank:]]*"?([[:digit:].]*)"?[[:blank:]]*$#\1#p')" [[ -n "$value" ]] && echo "$metric" "$value" done)" metrics_len="$(echo "$metrics" | wc -c)" echo 'HTTP/1.1 200 OK' echo "Content-Length: $metrics_len" echo 'Content-Type: text/plain' echo "Date: $(date -R -u | sed -r 's#\+0000$#GMT#')" echo echo "$metrics" return 0 } export -f get_metrics export -f read_config_file # periodically return metrics for the specified modules and targets when requested ncat -k -l 9089 -c 'read_config_file && get_metrics' # exit exit 0 baxic-snmp-exporter.0.1.0.linux-noarch/LICENSE0000644002342000234200000000033114043076357017773 0ustar baxicbaxicThis is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. baxic-snmp-exporter.0.1.0.linux-noarch/README0000644002342000234200000000456514043322104017643 0ustar baxicbaxic ---- Introduction Baxic SNMP Exporter is a Prometheus Exporter used to collect metrics from a monitored host using any SNMP OIDs configured in the configuration file. It's written in Bash and uses the ncat command to listen on TCP port 9089 and snmpwalk command to retrieve metrics from the target host. See online Wiki for more information: https://baxic.org/index.php/wikipedia/article/linux/monitoring/prometheus/exporters/baxic-snmp-exporter ---- Prerequisities The ncat tool must be present on the system. Moreover, /bih/sh must be a symlink to /bin/bash otherwise the function export doesn't work properly (note the export -f ... commands in the script). Furthermore, we need the snmpwalk command. ---- Installation # switch to root user mkdir -p /opt/prometheus-apps cd /opt/prometheus-apps # either clone a git repository git clone git://github.com/baxic-cz/baxic-snmp-exporter.git # or extract the tgz archive tar -xzf baxic-snmp-exporter*.tgz ln -s baxic-snmp-exporter.*.linux-noarch baxic-snmp-exporter cd baxic-snmp-exporter # check file permissions chmod a+x *.sh ls -l # configure metrics in baxic-snmp-exporter.conf, an example configuration follows, # each entry in the SNMP array consists of three fields separated by a colon, # the module name, the metric name the SNMP oid SNMP[0]='baxic_server:memory_total:1.3.6.1.4.1.2021.4.5.0' SNMP[1]='baxic_server:memory_free:1.3.6.1.4.1.2021.4.6.0' SNMP[10]='baxic_thermometer:temperature:0.1.3.6.1.4.1.21287.16.1.0' # define the exporter as a systemd service if required cp baxic-snmp-expoter.service /etc/systemd/system systemctl daemon-reload systemctl enable baxic-snmp-exporter.service ---- Running It's strongly recommended to run the script under non-privileged user. To start the service under the pre-configured nobody:nogroup user:group, run: systemctl start baxic-snmp-exporter.service Or if you want to run/test it just as a CLI command, run under the required user account: /opt/prometheus-apps/baxic-snmp-exporter/baxic-snmp-exporter.sh ---- Test functionality The returned metrics can be checked from a web-browser or from a command-line, e.g. using curl: curl -i 'http://localhost:9089/mertrics?module=baxic_server&target=localhost' ---- Summary The exporter is up and running now. You should consider protecting access to it on your firewall. You can now collect its metrics in a standard way using Prometheus.