Permalink
Browse files

added a new command to update elog-server

  • Loading branch information...
xianhuazhou committed Sep 18, 2012
1 parent 15262af commit 3832cf08aa6ed3fe5b026f659cca67f6b083c9a6
Showing with 32 additions and 61 deletions.
  1. +1 −1 bin/elog-client
  2. +6 −3 bin/elog-server
  3. +25 −11 lib/elog.coffee
  4. +0 −46 test/elog.coffee
View
@@ -6,7 +6,7 @@ os = require 'os'
TMP_POSITION_FILE = "elog.positions.json"
positionFile = os.tmpDir() + "/#{TMP_POSITION_FILE}"
-unless process.argv[2]
+if not process.argv[2] or process.argv[2].indexOf('help') != -1
console.log "elog-client can filter logs and send them to elog-server."
console.log "usage: elog-client /path/to/your/client.json # start elog-client"
console.log ""
View
@@ -1,15 +1,18 @@
#!/usr/bin/env coffee
elog = require(__dirname + '/../lib/elog.coffee').elog
-unless process.argv[2]
+if not process.argv[2] or process.argv[2].indexOf('help') != -1
console.log "elog-server can receive logs and store them into MongoDB, you can see the logs via web browsers."
console.log "e.g. http://localhost:3339"
console.log ""
console.log "Usage: elog-server /path/to/server/config.json # start elog-server"
console.log " elog-server reload # reload configuration"
console.log " elog-server stop # stop the current running process"
console.log " elog-server show-config # show the default configuration"
- console.log " elog-server /path/to/server/config.json update# update your elog server settings"
+ console.log " elog-server /path/to/server/config.json update <all|indexes|dupid># update your elog server settings"
+ console.log " all: update all possible changes"
+ console.log " indexes: update indexes of MongoDB"
+ console.log " dupid: update dupid (since v0.1.0)"
console.log ""
elog.showVersion()
@@ -20,7 +23,7 @@ configFile = argv2
# update elog-server
if process.argv[3] is 'update'
- elog.updateServer(require(configFile, true))
+ elog.updateServer(require(configFile, true), process.argv[4])
return
# run server
View
@@ -36,24 +36,38 @@ exports.elog = {
)
process.exit 0
- updateServer: (config) ->
+ updateServer: (config, action) ->
+ possibleActions = ['all', 'indexes', 'dupid']
+ if possibleActions.indexOf(action) is -1
+ console.log "Invalid update action given: #{action}"
+ console.log "Possible actions are #{possibleActions.join ', '}"
+ process.exit -1
+
console.log "Updating elog-server ..."
+
cfg = config.mongodb
utils = this.utils
+
myDB = new this.db(cfg.host, cfg.port, cfg.database, cfg.collection, false)
myDB.open (collection, db) ->
collection = db.collection(cfg.collection)
- console.log " >> updating indexes"
- myDB.createIndexes()
- collection.find().toArray (err, docs) ->
- console.log " >> updating dupids for show top X errors"
- for doc in docs
- return unless doc
- updatedData = {dupid: utils.md5(utils.trimLineTime(doc.msg))}
- collection.update({_id: doc._id}, {$set: updatedData})
+ if action is 'all' or action is 'indexes'
+ console.log " >> updating indexes"
+ myDB.createIndexes()
- console.log ""
- console.log "elog-server has been updated."
+ if action is 'all' or action is 'dupid'
+ collection.find().toArray (err, docs) ->
+ db.close()
+ console.log " >> updating dupid for show top X errors"
+ for doc in docs
+ return unless doc
+ return if doc.dupid
+ console.log "processing log #{doc._id}"
+ updatedData = {dupid: utils.md5(utils.trimLineTime(doc.msg))}
+ collection.update({_id: doc._id}, {$set: updatedData})
+ process.exit 0
+ else
+ db.close()
process.exit 0
reload: (program) ->
View
@@ -1,46 +0,0 @@
-elog = require('../lib/elog.coffee').elog
-db = elog.db
-
-describe 'elog', ->
- describe 'updateServer', ->
- config = {
- "mongodb": {
- "port": 27017,
- "host": "localhost",
- "database": "elogtest",
- "collection": "logs"
- }
- }
-
- mongoDB = null
- cfg = config.mongodb
- mongoDB = new elog.db(cfg.host, cfg.port, cfg.database, cfg.collection, false)
-
- mongoDB.db.open (err, db) ->
- db.createCollection(cfg.collection, (err, collection) ->
- collection.insert({
- hostname: 'hostname',
- app: 'app',
- level: 3,
- time: new Date().getTime(),
- dupid: 'blablamd5'
- }, {safe: true}, (err, docs) ->
- console.log err if err
- )
- )
-
- afterEach(->
- mongoDB.getCollection().drop()
- )
-
- it "can create indexes", ->
- elog.updateServer(config)
- mongoDB.getCollection().indexInformation (err, doc) ->
- indexes = []
- indexes.push(k) for k, v of doc
- indexes.should.include '_id_'
- indexes.should.include 'hostname'
- indexes.should.include 'app'
- indexes.should.include 'level'
- indexes.should.include 'time'
- indexes.should.include 'dupid'

0 comments on commit 3832cf0

Please sign in to comment.