Skip to content

Commit a2a0414

Browse files
committed
Adding some of the test scripts used when writing 1.3.
1 parent f2ae576 commit a2a0414

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

dnxmq/fakeworker.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import zmq, simplejson as json, time
2+
3+
zctx = zmq.Context()
4+
5+
jobs = zctx.socket(zmq.PULL)
6+
jobs.connect("ipc:///var/nagios/mqexecjobs.sock")
7+
results = zctx.socket(zmq.PUSH)
8+
results.connect("ipc:///var/nagios/mqexecresults.sock")
9+
10+
while True:
11+
job = jobs.recv()
12+
if jobs.getsockopt(zmq.RCVMORE) > 0:
13+
continue
14+
15+
job = json.loads(job)
16+
17+
keys = [ "host_name", "service_description",
18+
"check_options", "scheduled_check", "reschedule_check",
19+
"latency", "early_timeout", "check_type" ]
20+
out = { }
21+
for k in keys:
22+
if k not in job:
23+
continue
24+
out[k] = job[k]
25+
26+
# out['scheduled_check'] = 1
27+
# out['reschedule_check'] = 1
28+
out['output'] = "Test! Test! Test!\n"
29+
out['return_code'] = 0
30+
out['exited_ok'] = 1
31+
out['early_timeout'] = 0
32+
now = int(time.time())
33+
out['start_time'] = { 'tv_sec': now, 'tv_usec': 0 }
34+
out['finish_time'] = { 'tv_sec': now, 'tv_usec': 500 }
35+
out['type'] = 'service_check_processed' if 'service_description' in job \
36+
else 'host_check_processed'
37+
38+
results.send(json.dumps(out))

latencycheck.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import zmq, time, simplejson as json
2+
context = zmq.Context()
3+
4+
pub = context.socket(zmq.REQ)
5+
pub.connect("ipc:///var/nagios/nagmqstate.sock")
6+
start = time.time()
7+
8+
def get_latency():
9+
now = time.time()
10+
pub.send_json({ "list_hosts": True, "include_services": True, "keys": [ "latency", "type" ], "expand_lists": True})
11+
respraw = pub.recv()
12+
end = time.time()
13+
resp = json.loads(respraw)
14+
15+
svc_latency_max = 0
16+
svc_latency_avg = 0
17+
svcs_count = 0
18+
host_latency_max = 0
19+
host_latency_avg = 0
20+
hosts_count = 0
21+
22+
for obj in resp:
23+
if obj['type'] == 'service':
24+
svc_latency_max = max(svc_latency_max, obj['latency'])
25+
svc_latency_avg += obj['latency']
26+
svcs_count += 1
27+
elif obj['type'] == 'host':
28+
host_latency_max = max(host_latency_max, obj['latency'])
29+
host_latency_avg += obj['latency']
30+
hosts_count += 1
31+
32+
svc_latency_avg /= svcs_count
33+
host_latency_avg /= hosts_count
34+
35+
print "{0} {1} {2} {3} {4} {5}".format(now - start, end - now, svc_latency_max, svc_latency_avg, host_latency_max, host_latency_avg)
36+
37+
while time.time() - start < 60 * 60:
38+
get_latency()

0 commit comments

Comments
 (0)