I'm trying to build small and simple mmonit clone application with node.js, thats my first application in node and express and I've faced an issue with post data.
var
express = require('express'),
http = require('http'),
routes = require('./routes');
var app = express.createServer();
app.configure(function(){
app.set('port', process.env.PORT || 3001);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
app.configure('development', function(){
app.use(express.errorHandler());
});
app.post('/collector', function(req, res){
console.log( req.body ) ;
res.send("OK");
});
http.createServer(app).listen(app.get('port'), function() {
console.log("Express server listening on port " + app.get('port'));
});
When i'm redirecting the monit to rails application in console i can see the parsed params those are:
{"monit"=>{"services"=>{"service"=>[{"children"=>"1", "ppid"=>"1", "cpu"=>{"percenttotal"=>"0.0", "percent"=>"0.0"}, "monitormode"=>"0", "type"=>"3", "port"=>{"type"=>"TCP", "portnumber"=>"80", "protocol"=>"DEFAULT", "hostname"=>"127.0.0.1", "request"=>nil, "responsetime"=>"0.000"}, "status_hint"=>"0", "status"=>"0", "collected_sec"=>"1338639012", "uptime"=>"9867", "monitor"=>"1", "pid"=>"18574", "name"=>"nginx", "pendingaction"=>"0", "collected_usec"=>"429327", "memory"=>{"kilobytetotal"=>"2976", "percenttotal"=>"0.0", "percent"=>"0.0", "kilobyte"=>"1028"}}, {"system"=>{"cpu"=>{"system"=>"0.3", "user"=>"1.4", "wait"=>"0.0"}, "swap"=>{"percent"=>"0.0", "kilobyte"=>"52"}, "load"=>{"avg05"=>"0.60", "avg01"=>"0.70", "avg15"=>"0.54"}, "memory"=>{"percent"=>"43.6", "kilobyte"=>"2644604"}}, "monitormode"=>"0", "type"=>"5", "status_hint"=>"0", "status"=>"0", "collected_sec"=>"1338639012", "monitor"=>"1", "name"=>"system_cthulhu-laptop", "pendingaction"=>"0", "collected_usec"=>"429327"}]}, "version"=>"5.3.2", "server"=>{"startdelay"=>"0", "httpd"=>{"address"=>"localhost", "port"=>"3002", "ssl"=>"0"}, "uptime"=>"230", "controlfile"=>"/etc/monit/monitrc", "localhostname"=>"cthulhu-laptop", "poll"=>"5"}, "platform"=>{"cpu"=>"8", "release"=>"3.2.0-24-generic", "version"=>"#39-Ubuntu SMP Mon May 21 16:52:17 UTC 2012", "swap"=>"6236156", "machine"=>"x86_64", "name"=>"Linux", "memory"=>"6060628"}, "incarnation"=>"1338638782", "servicegroups"=>nil, "id"=>"357366846a5b24d5d4d740a42a62af48"}}
Thanks for help.