Révision dbb9ecfc
Initial version
| plugins/other/femon | ||
|---|---|---|
| 1 |
#!/usr/bin/env python |
|
| 2 |
# -*- encoding: iso-8859-1 -*- |
|
| 3 |
# |
|
| 4 |
# Wildcard-plugin to monitor DVB signal information via femon command line utility, |
|
| 5 |
# |
|
| 6 |
# To monitor a dvb device, link femon_<device> to this file. |
|
| 7 |
# E.g. |
|
| 8 |
# ln -s /usr/share/munin/plugins/femon_ /etc/munin/plugins/femon_adapter0 |
|
| 9 |
# ...will monitor /dev/dvb/adapter0. |
|
| 10 |
# |
|
| 11 |
# Needs following minimal configuration in plugin-conf.d/munin-node: |
|
| 12 |
# [femon_*] |
|
| 13 |
# user root |
|
| 14 |
# |
|
| 15 |
# Parameters |
|
| 16 |
# femonpath - Specify path to femon program (Default: /usr/bin/femon) |
|
| 17 |
# |
|
| 18 |
# Author: Nicolas Knotzer <nknotzer@gmail.com> |
|
| 19 |
# |
|
| 20 |
# v1.0 02/10/2011 |
|
| 21 |
# |
|
| 22 |
# Copyright (c) 2011 Nicolas Knotzer. |
|
| 23 |
# |
|
| 24 |
# The smart_ plugin by Nicolas Stransky <Nico@stransky.cx> was used as a template! |
|
| 25 |
# |
|
| 26 |
# Permission to use, copy, and modify this software with or without fee |
|
| 27 |
# is hereby granted, provided that this entire notice is included in |
|
| 28 |
# all source code copies of any software which is or includes a copy or |
|
| 29 |
# modification of this software. |
|
| 30 |
# |
|
| 31 |
# THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR |
|
| 32 |
# IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY |
|
| 33 |
# REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE |
|
| 34 |
# MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR |
|
| 35 |
# PURPOSE. |
|
| 36 |
# |
|
| 37 |
# |
|
| 38 |
# Magic markers |
|
| 39 |
#%# capabilities=autoconf suggest |
|
| 40 |
#%# family=auto |
|
| 41 |
|
|
| 42 |
## You may edit the following 2 variables |
|
| 43 |
# Increase verbosity (True/False) |
|
| 44 |
verbose=False |
|
| 45 |
# Modify to your needs: |
|
| 46 |
statefiledir='/var/lib/munin/plugin-state' |
|
| 47 |
# You may not modify anything below this line |
|
| 48 |
|
|
| 49 |
import os, sys, string, subprocess |
|
| 50 |
from math import log |
|
| 51 |
plugin_version="1.0" |
|
| 52 |
|
|
| 53 |
def verboselog(s): |
|
| 54 |
global plugin_name |
|
| 55 |
sys.stderr.write(plugin_name+': '+s+'\n') |
|
| 56 |
|
|
| 57 |
if not verbose : |
|
| 58 |
verboselog = lambda s: None |
|
| 59 |
|
|
| 60 |
def find_dvb_adapters() : |
|
| 61 |
adapters=[] |
|
| 62 |
if os.path.exists('/dev/dvb/'):
|
|
| 63 |
try : |
|
| 64 |
for adapter in os.listdir('/dev/dvb/') :
|
|
| 65 |
try : |
|
| 66 |
verboselog('Found '+adapter+'...')
|
|
| 67 |
adapters.append(adapter) |
|
| 68 |
except : |
|
| 69 |
continue |
|
| 70 |
except : |
|
| 71 |
verboselog('Failed to list adapters in /dev/dvb')
|
|
| 72 |
return(adapters) |
|
| 73 |
|
|
| 74 |
def get_dvb_adapter_name() : |
|
| 75 |
global plugin_name |
|
| 76 |
try : |
|
| 77 |
name=[plugin_name[string.rindex(plugin_name,'_')+1:]] |
|
| 78 |
|
|
| 79 |
# Check that the adapter exists in /dev/dvb |
|
| 80 |
if not os.path.exists('/dev/dvb/'+name[0]):
|
|
| 81 |
verboselog('/dev/dvb/'+name[0]+' not found!')
|
|
| 82 |
sys.exit(1) |
|
| 83 |
return(name) |
|
| 84 |
except : |
|
| 85 |
verboselog('No dvb adapter name found in plugin\'s symlink!')
|
|
| 86 |
sys.exit(1) |
|
| 87 |
|
|
| 88 |
def print_adapter_config(dvb_adapter) : |
|
| 89 |
verboselog('Printing configuration')
|
|
| 90 |
print ('graph_title DVB Femon Sensors '+dvb_adapter[0])
|
|
| 91 |
print ('graph_args -l 0')
|
|
| 92 |
print ('graph_vlabel Quality')
|
|
| 93 |
print ('graph_category DVB')
|
|
| 94 |
print ('graph_info This graph shows the femon values for your DVB '+dvb_adapter[0])
|
|
| 95 |
|
|
| 96 |
print ('str.label Signal Strength')
|
|
| 97 |
print ('str.info Signal Strength')
|
|
| 98 |
print ('str.draw LINE2')
|
|
| 99 |
|
|
| 100 |
print ('snr.label Signal-to-Noise Ratio')
|
|
| 101 |
print ('snr.info Signal-to-Noise Ratio')
|
|
| 102 |
print ('snr.draw LINE2')
|
|
| 103 |
|
|
| 104 |
print ('ber.label Bit Error Rate')
|
|
| 105 |
print ('ber.info Bit Error Rate')
|
|
| 106 |
print ('ber.draw LINE2')
|
|
| 107 |
|
|
| 108 |
print ('unc.label Uncorrected Blocks')
|
|
| 109 |
print ('unc.info Uncorrected Blocks')
|
|
| 110 |
print ('unc.draw LINE2')
|
|
| 111 |
|
|
| 112 |
|
|
| 113 |
def print_dvb_adapter_values(dvb_adapter) : |
|
| 114 |
try : |
|
| 115 |
|
|
| 116 |
verboselog('Reading values from '+dvb_adapter[0])
|
|
| 117 |
femon_output=subprocess.check_output([os.getenv('femonpath','/usr/bin/femon'), '-H', '-c 1', '-a '+dvb_adapter[0].replace('adapter','')])
|
|
| 118 |
verboselog(femon_output) |
|
| 119 |
except : |
|
| 120 |
verboselog('Cannot access femon values! Check user rights or proper femon installation.')
|
|
| 121 |
sys.exit(1) |
|
| 122 |
splitstr=femon_output.split ('|')
|
|
| 123 |
print ('str.value '+splitstr[1].replace('signal','').strip(' %'))
|
|
| 124 |
print ('snr.value '+splitstr[2].replace('snr','').strip(' %'))
|
|
| 125 |
print ('ber.value '+splitstr[3].replace('ber','').strip(' '))
|
|
| 126 |
print ('unc.value '+splitstr[4].replace('unc','').strip(' '))
|
|
| 127 |
|
|
| 128 |
|
|
| 129 |
### Main part ### |
|
| 130 |
|
|
| 131 |
plugin_name=list(os.path.split(sys.argv[0]))[1] |
|
| 132 |
verboselog('plugins\' UID: '+str(os.geteuid())+' / plugins\' GID: '+str(os.getegid()))
|
|
| 133 |
|
|
| 134 |
# Parse arguments |
|
| 135 |
if len(sys.argv)>1 : |
|
| 136 |
if sys.argv[1]=="config" : |
|
| 137 |
dvb_adapter=get_dvb_adapter_name() |
|
| 138 |
print_adapter_config (dvb_adapter) |
|
| 139 |
sys.exit(0) |
|
| 140 |
elif sys.argv[1]=="autoconf" : |
|
| 141 |
if os.path.exists(os.getenv('femonpath','/usr/bin/femon')) :
|
|
| 142 |
if not find_dvb_adapters(): |
|
| 143 |
print('no (no dvb adapters accessible)')
|
|
| 144 |
else : |
|
| 145 |
print('yes')
|
|
| 146 |
sys.exit(0) |
|
| 147 |
else : |
|
| 148 |
print('no (femon not found)')
|
|
| 149 |
sys.exit(0) |
|
| 150 |
elif sys.argv[1]=="suggest" : |
|
| 151 |
for adapter in find_dvb_adapters() : |
|
| 152 |
print(adapter) |
|
| 153 |
sys.exit(0) |
|
| 154 |
elif sys.argv[1]=="version" : |
|
| 155 |
print('femon_ Munin plugin, version '+plugin_version)
|
|
| 156 |
sys.exit(0) |
|
| 157 |
elif sys.argv[1]!="" : |
|
| 158 |
verboselog('unknown argument "'+sys.argv[1]+'"')
|
|
| 159 |
sys.exit(1) |
|
| 160 |
|
|
| 161 |
# No argument given, doing the real job: |
|
| 162 |
dvb_adapter=get_dvb_adapter_name() |
|
| 163 |
print_dvb_adapter_values (dvb_adapter) |
|
| 164 |
exit(0) |
|
| 165 |
|
|
| 166 |
|
|
| 167 |
### The following is the _ plugin documentation, intended to be used with munindoc |
|
| 168 |
""" |
|
| 169 |
=head1 NAME |
|
| 170 |
|
|
| 171 |
femon_ - Munin wildcard-plugin to monitor dvb signal information attribute values through femon |
|
| 172 |
|
|
| 173 |
=head1 APPLICABLE SYSTEMS |
|
| 174 |
|
|
| 175 |
Node with B<Python> interpreter and B<femon> |
|
| 176 |
installed and in function. |
|
| 177 |
|
|
| 178 |
=head1 CONFIGURATION |
|
| 179 |
|
|
| 180 |
=head2 Create link in service directory |
|
| 181 |
|
|
| 182 |
To monitor a dvb device, create a link in the service directory |
|
| 183 |
of the munin-node named femon_<device>, which is pointing to this file. |
|
| 184 |
|
|
| 185 |
E.g. |
|
| 186 |
|
|
| 187 |
ln -s /usr/share/munin/plugins/femon_ /etc/munin/plugins/femon_adapter0 |
|
| 188 |
|
|
| 189 |
...will monitor /dev/dvb/adapter0. |
|
| 190 |
|
|
| 191 |
=head2 Grant privileges in munin-node |
|
| 192 |
|
|
| 193 |
The plugin must be run under high privileged user B<root>, to get access to the raw device. |
|
| 194 |
|
|
| 195 |
So following minimal configuration in plugin-conf.d/munin-node is needed. |
|
| 196 |
|
|
| 197 |
=over 2 |
|
| 198 |
|
|
| 199 |
[femon_*] |
|
| 200 |
user root |
|
| 201 |
|
|
| 202 |
=back |
|
| 203 |
|
|
| 204 |
=head2 Set Parameter if needed |
|
| 205 |
|
|
| 206 |
femonpath - Specify path to femon program (Default: /usr/bin/femon) |
|
| 207 |
|
|
| 208 |
=head1 INTERPRETATION |
|
| 209 |
|
|
| 210 |
|
|
| 211 |
=head1 MAGIC MARKERS |
|
| 212 |
|
|
| 213 |
#%# family=auto |
|
| 214 |
#%# capabilities=autoconf suggest |
|
| 215 |
|
|
| 216 |
=head1 CALL OPTIONS |
|
| 217 |
|
|
| 218 |
B<none> |
|
| 219 |
|
|
| 220 |
=over 2 |
|
| 221 |
|
|
| 222 |
Fetches values if called without arguments: |
|
| 223 |
|
|
| 224 |
E.g.: munin-run femon_adapter0 |
|
| 225 |
|
|
| 226 |
=back |
|
| 227 |
|
|
| 228 |
B<config> |
|
| 229 |
|
|
| 230 |
=over 2 |
|
| 231 |
|
|
| 232 |
Prints plugins configuration. |
|
| 233 |
|
|
| 234 |
E.g.: munin-run femon_adapter0 config |
|
| 235 |
|
|
| 236 |
=back |
|
| 237 |
|
|
| 238 |
B<autoconf> |
|
| 239 |
|
|
| 240 |
=over 2 |
|
| 241 |
|
|
| 242 |
Tries to find femon and outputs value 'yes' for success, 'no' if not. |
|
| 243 |
|
|
| 244 |
It's used by B<munin-node-configure> to see wether autoconfiguration is possible. |
|
| 245 |
|
|
| 246 |
=back |
|
| 247 |
|
|
| 248 |
B<suggest> |
|
| 249 |
|
|
| 250 |
=over 2 |
|
| 251 |
|
|
| 252 |
Outputs the list of device names, that it found plugged to the system. |
|
| 253 |
|
|
| 254 |
B<munin-node-configure> use this to build the service links for this wildcard-plugin. |
|
| 255 |
|
|
| 256 |
=back |
|
| 257 |
|
|
| 258 |
=head1 VERSION |
|
| 259 |
|
|
| 260 |
Version 1.0 |
|
| 261 |
|
|
| 262 |
=head1 BUGS |
|
| 263 |
|
|
| 264 |
None known |
|
| 265 |
|
|
| 266 |
=head1 AUTHOR |
|
| 267 |
|
|
| 268 |
(C) 2011 Nicolas Knotzer <nknotzer@gmail.com> |
|
| 269 |
|
|
| 270 |
The smart_ plugin by Nicolas Stransky <Nico@stransky.cx> was used as a template! |
|
| 271 |
|
|
| 272 |
=head1 LICENSE |
|
| 273 |
|
|
| 274 |
GPLv2 (http://www.gnu.org/licenses/gpl-2.0.txt) |
|
| 275 |
|
|
| 276 |
=cut |
|
| 277 |
|
|
| 278 |
|
|
| 279 |
""" |
|
Formats disponibles : Unified diff