Repository
Munin (contrib)
Last change
2022-01-09
Graph Categories
Family
manual
Capabilities
Keywords
Language
Python (3.x)
License
GPL-3.0-only
Authors

exodus_

Name

exodus_ - Exodus wildcard-plugin to monitor an Exodus instance.

This wildcard plugin provides the suffixes applications, reports and trackers.

Installation

- Copy this plugin in your munin plugins directory

ln -s /usr/share/munin/plugins/exodus_ /etc/munin/plugins/exodus_applications
ln -s /usr/share/munin/plugins/exodus_ /etc/munin/plugins/exodus_reports
ln -s /usr/share/munin/plugins/exodus_ /etc/munin/plugins/exodus_trackers

After the installation you need to restart your munin-node service.

Configuration

You need to create a file named exodus placed in the directory /etc/munin/plugin-conf.d/ with the following config:

[exodus_*]
env.exodus_url https://reports.exodus-privacy.eu.org
env.exodus_token your-api-token

Authors

Codimp contact@lithio.fr

License

GPLv3

Magic Markers

#%# family=manual
#%# capabilities=suggest
#!/usr/bin/env python3
"""
=head1 NAME

exodus_ - Exodus wildcard-plugin to monitor an L<Exodus|https://github.com/Exodus-Privacy/exodus/>
instance.

This wildcard plugin provides the suffixes C<applications>, C<reports> and C<trackers>.

=head1 INSTALLATION

- Copy this plugin in your munin plugins directory

=over 2

    ln -s /usr/share/munin/plugins/exodus_ /etc/munin/plugins/exodus_applications
    ln -s /usr/share/munin/plugins/exodus_ /etc/munin/plugins/exodus_reports
    ln -s /usr/share/munin/plugins/exodus_ /etc/munin/plugins/exodus_trackers

=back

After the installation you need to restart your munin-node service.

=head1 CONFIGURATION

You need to create a file named exodus placed in the directory
/etc/munin/plugin-conf.d/ with the following config:

=over 2

    [exodus_*]
    env.exodus_url https://reports.exodus-privacy.eu.org
    env.exodus_token your-api-token

=back

=head1 AUTHORS

Codimp <contact@lithio.fr>

=head1 LICENSE

GPLv3

=head1 MAGIC MARKERS

 #%# family=manual
 #%# capabilities=suggest

=cut
"""

import os
import sys
import json
import urllib.request


def print_count(element):
    endpoint = os.getenv("exodus_url") + "/api/" + element + "/count"
    headers = {"Authorization": "Token " + os.getenv("exodus_token")}
    request = urllib.request.Request(endpoint, method="POST", headers=headers)
    with urllib.request.urlopen(request) as connection:
        if connection.getcode() == 200:
            count = json.loads(connection.read())["count"]
            print(element + ".value", count)


def main():
    try:
        mode = sys.argv[1]
    except IndexError:
        mode = ""
    wildcard = sys.argv[0].split("exodus_")[1]

    if mode == "suggest":
        print("applications")
        print("reports")
        print("trackers")
        exit(0)

    if wildcard == "applications":
        if mode == "config":
            print("graph_title Exodus applications")
            print("graph_vlabel applications")
            print("graph_category exodus")
            print("applications.label Applications")
        else:
            print_count("applications")
    elif wildcard == "reports":
        if mode == "config":
            print("graph_title Exodus reports")
            print("graph_vlabel reports")
            print("graph_category exodus")
            print("reports.label Reports")
        else:
            print_count("reports")
    elif wildcard == "trackers":
        if mode == "config":
            print("graph_title Exodus trackers")
            print("graph_vlabel trackers")
            print("graph_category exodus")
            print("trackers.label Trackers")
        else:
            print_count("trackers")


if __name__ == "__main__":
    main()