Permalink
Browse files

Add UDP (datagram) service

  • Loading branch information...
brandonhamilton committed Feb 29, 2012
1 parent fc51700 commit 0268b4c68714cb319a7f64450983e9762ba3912a
Showing with 27 additions and 0 deletions.
  1. +27 −0 api.js
View
27 api.js
@@ -2,6 +2,8 @@ var http = require('http');
var https = require('https');
var net = require('net');
var fs = require('fs');
+var dgram = require('dgram');
+var Buffer = require('buffer').Buffer;
var logger = require('util');
var _ = require('underscore')._;
var settings = require('./settings').create();
@@ -198,6 +200,31 @@ var commands = {
controller.emit(service.status, service);
});
},
+ udp : function(serviceDefinition, service) {
+ var sock = dgram.createSocket("udp4");
+ sock.on("message", function (buffer, from) {
+ if (!serviceDefinition.rcv || serviceDefinition.rcv == buffer) {
+ service.status = "up";
+ service.statusCode = 0;
+ service.message = "";
+ } else {
+ service.status = "critical";
+ service.statusCode = 0;
+ service.message = "Expected " + serviceDefinition.rcv + " but was '" + buffer;
+ }
+ sock.close();
+ controller.emit(service.status, service);
+ });
+ sock.on("error", function (exception) {
+ service.status = "down";
+ service.statusCode = 0;
+ service.message = exception;
+ controller.emit(service.status, service);
+ sock.close();
+ });
+ var buf = new Buffer(serviceDefinition.cmd);
+ sock.send(buf, 0, buf.length, serviceDefinition.port, serviceDefinition.host);
+ },
ftp : function(serviceDefinition, service) {
service.status = "unknown";
service.statusCode = 0;

0 comments on commit 0268b4c

Please sign in to comment.