Permalink
Browse files

Revert 41d4e4d^..HEAD

  • Loading branch information...
1 parent 41d4e4d commit 4f8edaa61ad34b0d4a9294c43441102639305750 @slyons committed Sep 9, 2011
Showing with 3 additions and 94 deletions.
  1. +2 −17 lib/collectd.js
  2. +0 −76 lib/collectd/types.js
  3. +1 −1 package.json
View
19 lib/collectd.js
@@ -1,7 +1,4 @@
var protocol = require("./collectd/protocol"),
- types = require("./collectd/types"),
- path = require("path"),
- fs = require("fs"),
events = require("events"),
dgram = require("dgram"),
util = require("util");
@@ -13,14 +10,7 @@ DEFAULT_IPv6_GROUP = "ff18::efc0:4a42"
var CollectDReceiver = exports.Receiver = function(options){
var self = this;
- self.options = options
-
- if(options.typesdb != null && path.existsSync(options.typesdb)){
- fs.readFile(options.typesdb, "ascii", function(err, data){
- if(err) throw err;
- self.typesdb = types.parse_typedb(data);
- });
- }
+ self.options = options;
self.server = null;
if(options.server){
@@ -40,9 +30,6 @@ var CollectDReceiver = exports.Receiver = function(options){
self.server.on("message", function(msg, rinfo){
try{
results = protocol.collectd_parse(new Buffer(msg));
- if(self.typesdb){
- results = types.wrap_results(results, self.typesdb);
- }
self.emit("values", results[0]);
self.emit("notifications", results[1]);
} catch(err){
@@ -52,6 +39,4 @@ var CollectDReceiver = exports.Receiver = function(options){
}
-util.inherits(CollectDReceiver, events.EventEmitter);
-
-exports.parse_typedb = types.parse_typedb;
+util.inherits(CollectDReceiver, events.EventEmitter);
View
76 lib/collectd/types.js
@@ -1,76 +0,0 @@
-var fs = require("fs");
-
-var line_regex = /^(\S+)\s+(.*)$/;
-var val_regex = /(\w+):(\w+):-?(\d+|U):(\d+|U)$/i;
-
-function parse_typedb(content){
- if('string' === typeof content){
- content = content.split("\n");
- }
-
- types = new Array();
- content.forEach(function(line, index){
- line = line.trim();
- if(line[0] == "#" || line.length == 0)
- return;
-
- var match = line_regex.exec(line);
- if(match != null){
- types[match[1]] = parse_value_description(match[2]);
- } else {
- console.error("Line does not match: ", line);
- }
- });
- return types;
-}
-
-function parse_value_description(descs){
- if(descs.search(",") == -1 ){
- descs = [descs];
- } else {
- descs = descs.split(",");
- }
-
- dobjs = new Array();
- descs.forEach(function(descr, index){
- match = val_regex.exec(descr);
- if(match != null){
- dobjs.push({
- name:match[1],
- type:match[2],
- min:match[3],
- max:match[4]
- });
- } else {
- console.error("Value does not match: ", descr);
- }
- });
- return dobjs;
-}
-
-function wrap_results(results, types){
- results.forEach(function(result_type, index){
- result_type.forEach(function(result){
- console.log(result);
- if(result.type in types){
- var newdata = new Array();
- type = types[result.type];
- result.data.forEach(function(datum, i){
- if(type[i] != null){
- datum["name"] = type[i].name;
- datum["type"] = type[i].type;
- datum["min"] = type[i].min;
- datum["max"] = type[i].max;
- datum["value"] = datum[1];
- }
- });
- } else {
- console.log(result.type, " is not a known type.");
- }
- });
- });
- return results;
-}
-
-exports.parse_typedb = parse_typedb;
-exports.wrap_results = wrap_results;
View
2 package.json
@@ -2,7 +2,7 @@
"author": "Scott Lyons <scottalyons@gmail.com>",
"name": "collectd",
"description": "A NodeJS module for receiving and parsing the CollectD binary protocol",
- "version": "0.0.1",
+ "version": "0.0.0",
"repository": {
"type": "git",
"url": "git://github.com/slyons/node-collectd.git"

0 comments on commit 4f8edaa

Please sign in to comment.