Last active
August 29, 2015 14:10
-
-
Save ties/8e6f41d5931fd8463873 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pynetgear import Netgear | |
| import operator | |
| import collections | |
| import argparse | |
| import os | |
| """ | |
| A simple plugin to have wlan stats in Munin | |
| The plugin has sensible defaults. If you have different settings, | |
| add some of the following lines to the munin plugin config | |
| ```python | |
| [wlan_stats] | |
| env.NETGEAR_HOST 192.168.1.1 | |
| env.NETGEAR_USER admin | |
| env.NETGEAR_PASS password | |
| ``` | |
| """ | |
| if __name__ == "__main__": | |
| parser = argparse.ArgumentParser('Munin Netgear stats') | |
| parser.add_argument('config', nargs='?', help='Print config') | |
| args = parser.parse_args() | |
| if args.config: | |
| print("""\ | |
| graph_title Number of network clients | |
| graph_args -l 0 | |
| graph_vlabel #clients | |
| graph_category network | |
| graph_info Number of connected clients to Netgear router | |
| wired.label wired | |
| wireless.label wireless | |
| wired.colour COLOUR0 | |
| wireless.colour COLOUR1\ | |
| """) | |
| else: | |
| host = os.environ.get('NETGEAR_HOST', '192.168.1.1') | |
| user = os.environ.get('NETGEAR_USER', 'admin') | |
| pw = os.environ.get('NETGEAR_PASS', 'password') | |
| ng = Netgear(host, user, pw) | |
| # Group by client type | |
| client_type = operator.attrgetter('type') | |
| types = collections.Counter(client_type(c) for c | |
| in ng.get_attached_devices()) | |
| # counter always contains a 0 - no need to get(0) | |
| print("wired.value {}".format(types['wired'])) | |
| print("wireless.value {}".format(types['wireless'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment