Blame view

index.js 2 KB
adfda8e1   Arsisakarn Srilatanart   initial commit fr...
1
2
3
4
5
6
7
8
9
10
var _ = require('lodash');
var moment = require('moment');
var log = require('./model/log');
var stat = require('./model/stat');
var alarm = require('./model/alarm');
var validate = require('./lib/validate');
var joi = require('joi');

module.exports = {

885ab5d1   Apichat.Tum   add filename
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
    /*
     * opts: {
     * 	 log: [dirname, rotation, maxsize]
     * 	 stat: [dirname, rotation, maxsize, interval, key]
     * 	 alarm: [dirname, rotation, maxsize]
     * }
     */
    init: function (opts) {
        var logstatalarm = undefined;
        validate.joi(opts, this.getSchema(), function (err, opts) {
            if (err) {
                throw new Error(err);
            }
        });
        return {
            log: new log(opts.dirname, opts.log),
            stat: new stat(opts.dirname, opts.stat, opts.alarm)
        };
    },
adfda8e1   Arsisakarn Srilatanart   initial commit fr...
30

885ab5d1   Apichat.Tum   add filename
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
    /*
     * Pre-define schema
     */
    getSchema: function () {
        return joi.object().keys({
            dirname: joi.string().required(),
            log: joi.object().keys({
                rotation: joi.number().min(0),
                maxsize: joi.number().min(0),
                filename: joi.string()
            }).required(),
            stat: joi.object().keys({
                rotation: joi.number().min(0),
                maxsize: joi.number().min(0),
                filename: joi.string(),
                interval: joi.number().min(0),
                data: joi.array().items(joi.object().keys({
                    key: joi.string().required(),
                    threshold: joi.number().min(0),
                    threshold_inv: joi.number().min(0)
                }))
            }).required(),
            alarm: joi.object().keys({
                rotation: joi.number().min(0),
                maxsize: joi.number().min(0),
                filename: joi.string(),
                external: joi.array().items(joi.object().keys({
                    fn: joi.func().required(),
                    args: joi.array().items(joi.any())
                }))
            }).required()
        });
    }
};