Skip to content
This repository has been archived by the owner on May 9, 2018. It is now read-only.

Commit

Permalink
Adding some of the test scripts used when writing 1.3.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbreams committed Jan 1, 2013
1 parent f2ae576 commit a2a0414
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
38 changes: 38 additions & 0 deletions dnxmq/fakeworker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import zmq, simplejson as json, time

zctx = zmq.Context()

jobs = zctx.socket(zmq.PULL)
jobs.connect("ipc:///var/nagios/mqexecjobs.sock")
results = zctx.socket(zmq.PUSH)
results.connect("ipc:///var/nagios/mqexecresults.sock")

while True:
job = jobs.recv()
if jobs.getsockopt(zmq.RCVMORE) > 0:
continue

job = json.loads(job)

keys = [ "host_name", "service_description",
"check_options", "scheduled_check", "reschedule_check",
"latency", "early_timeout", "check_type" ]
out = { }
for k in keys:
if k not in job:
continue
out[k] = job[k]

# out['scheduled_check'] = 1
# out['reschedule_check'] = 1
out['output'] = "Test! Test! Test!\n"
out['return_code'] = 0
out['exited_ok'] = 1
out['early_timeout'] = 0
now = int(time.time())
out['start_time'] = { 'tv_sec': now, 'tv_usec': 0 }
out['finish_time'] = { 'tv_sec': now, 'tv_usec': 500 }
out['type'] = 'service_check_processed' if 'service_description' in job \
else 'host_check_processed'

results.send(json.dumps(out))
38 changes: 38 additions & 0 deletions latencycheck.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import zmq, time, simplejson as json
context = zmq.Context()

pub = context.socket(zmq.REQ)
pub.connect("ipc:///var/nagios/nagmqstate.sock")
start = time.time()

def get_latency():
now = time.time()
pub.send_json({ "list_hosts": True, "include_services": True, "keys": [ "latency", "type" ], "expand_lists": True})
respraw = pub.recv()
end = time.time()
resp = json.loads(respraw)

svc_latency_max = 0
svc_latency_avg = 0
svcs_count = 0
host_latency_max = 0
host_latency_avg = 0
hosts_count = 0

for obj in resp:
if obj['type'] == 'service':
svc_latency_max = max(svc_latency_max, obj['latency'])
svc_latency_avg += obj['latency']
svcs_count += 1
elif obj['type'] == 'host':
host_latency_max = max(host_latency_max, obj['latency'])
host_latency_avg += obj['latency']
hosts_count += 1

svc_latency_avg /= svcs_count
host_latency_avg /= hosts_count

print "{0} {1} {2} {3} {4} {5}".format(now - start, end - now, svc_latency_max, svc_latency_avg, host_latency_max, host_latency_avg)

while time.time() - start < 60 * 60:
get_latency()

0 comments on commit a2a0414

Please sign in to comment.