Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for netdata slaves #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions netdata_to_nagios.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
# - nginx_local.connections : Check nginx connections
# - nginx_local.requests : Check nginx request rate
# - mdstat.mdstat_health : Check if there is a faulty md raid array
# -s, --slave
# Get data from the specified slave, instead of the host connected to
# -i interval
# Specify an interval in seconds (minimum 2)
# Default : 60
Expand Down Expand Up @@ -94,6 +96,10 @@ def usage():
- mdstat.mdstat_health : Check if there is a faulty md raid array
- apache_local.workers : Check apache worker utilization
- nginx_local.connections : Check nginx connections

-s, --slave
Get data from the specified slave, instead of the host connected to

-i interval
Specify an interval in seconds (minimum 2)
Default : 60
Expand Down Expand Up @@ -146,13 +152,15 @@ def init_datastruct(warn,crit):

return datastruct

def get_simple_datasource(hostaddress,port,datasource,interval):
def get_simple_datasource(hostaddress,port,slave,datasource,interval):
URL = ""
if (abs(int(interval)) < 1) or (abs(int(interval)) > 3600):
print "Interval problem, should be between 1 and 3600: " + interval
return None

URL = 'http://'+hostaddress+':'+port+'/api/v1/data?chart='+datasource+'&after='+interval+'&options=seconds'
slave_url = ""
if slave != "": slave_url = '/host/'+slave
URL = 'http://'+hostaddress+':'+port+slave_url+'/api/v1/data?chart='+datasource+'&after='+interval+'&options=seconds'

req = urllib2.Request(URL)

Expand All @@ -165,9 +173,9 @@ def get_simple_datasource(hostaddress,port,datasource,interval):
return json.loads(res.read())


def analyze_from_datasource(hostaddress,port,datasource,interval,warn,crit):
def analyze_from_datasource(hostaddress,port,slave,datasource,interval,warn,crit):

datapoints = get_simple_datasource(hostaddress,port,datasource,interval)
datapoints = get_simple_datasource(hostaddress,port,slave,datasource,interval)

if re.match('disk_util',datasource) != None:
splitted_datasource = re.split('(disk_util).(\w+)',datasource)
Expand Down Expand Up @@ -198,8 +206,8 @@ def analyze_from_datasource(hostaddress,port,datasource,interval,warn,crit):
datasource_connections = re.sub(r'(apache.*).workers',r'\1.connections', datasource)
datasource_requests = re.sub(r'(apache.*).workers',r'\1.requests', datasource)

apache_connections = get_simple_datasource(hostaddress,port,datasource_connections,interval)
apache_requests = get_simple_datasource(hostaddress,port,datasource_requests,interval)
apache_connections = get_simple_datasource(hostaddress,port,slave,datasource_connections,interval)
apache_requests = get_simple_datasource(hostaddress,port,slave,datasource_requests,interval)

return_value = analyze_apache_workers(datapoints, apache_connections, apache_requests, warn,crit)

Expand Down Expand Up @@ -668,14 +676,15 @@ def analyze_cpu_per_process(datapoints,warn,crit):

def main(argv):
try:
opts, args = getopt.getopt(argv,"hD:i:w:c:H:p:",["help","datasource=","interval=","warning=","critical=","host=","port="])
opts, args = getopt.getopt(argv,"hD:i:w:c:H:p:s:",["help","datasource=","interval=","warning=","critical=","host=","port=","slave="])
except getopt.GetoptError:
print usage()
sys.exit(3)
hostaddress = '127.0.0.1'
port = '19999'
interval = '-60'
datasource = 'apps.cpu'
slave = ''

for opt, arg in opts:
if opt in ('-h', "--help"):
Expand All @@ -693,6 +702,8 @@ def main(argv):
datasource = arg
elif opt in ("-i", "--interval"):
interval= str(0-int(arg))
elif opt in ("-s","--slave"):
slave = arg

try:
warning
Expand All @@ -708,7 +719,7 @@ def main(argv):
print usage()
sys.exit(3)

return_values = analyze_from_datasource(hostaddress,port,datasource,interval,warning,critical)
return_values = analyze_from_datasource(hostaddress,port,slave,datasource,interval,warning,critical)
if return_values is None:
sys.exit(3)
print return_values['output']
Expand Down