File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed
contrib/scripts/isc_dhpcd_graphite Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change 1313import pickle
1414import re
1515import socket
16+ import string
1617import struct
1718import subprocess
1819import sys
1920from time import time
2021
21- from nav .metrics .names import escape_metric_name
22-
23-
2422DEFAULT_PREFIX = "nav.dhcp"
2523DEFAULT_CONFIG_FILE = "/etc/dhcpd/dhcpd.conf"
2624DEFAULT_CMD_PATH = pathlib .Path ("/usr/bin/dhcpd-pools" )
2927
3028# graphite likes pickle protocol 2. Python 3: 3, Python 3.8+: 4
3129PICKLE_PROTOCOL = range (0 , pickle .HIGHEST_PROTOCOL + 1 )
30+ LEGAL_METRIC_CHARACTERS = string .ascii_letters + string .digits + "-_"
3231FLAGS = "-f j"
3332METRIC_MAPPER = {
3433 "defined" : "max" ,
4241Metric = namedtuple ("Metric" , ["path" , "value" , "timestamp" ])
4342
4443
44+ # vendored from nav.metrics.names.escape_metric_name
45+ def escape_metric_name (name ):
46+ """
47+ Escapes any character of `name` that may not be used in graphite metric
48+ names.
49+ """
50+ if name is None :
51+ return name
52+ name = name .replace ('\x00 ' , '' ) # some devices have crazy responses!
53+ name = '' .join ([c if c in LEGAL_METRIC_CHARACTERS else "_" for c in name ])
54+ return name
55+
56+
4557# parse comand line flags
4658def parse_args ():
4759 parser = argparse .ArgumentParser (description = "Send dhcp stats to graphite" )
You can’t perform that action at this time.
0 commit comments