-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendlog.js
40 lines (35 loc) · 1.04 KB
/
sendlog.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const co = require('co');
const config = require('./config');
const account = require('./account');
const AppPot = require('./apppot-sdk-lite');
const macAddr = process.argv[2];
const message = process.argv[3];
co(function*(){
// AppPot API呼び出し準備
const authInfo = new AppPot.AuthInfo();
const conf = new AppPot.Config(config, macAddr);
const ajax = new AppPot.Ajax(authInfo, conf);
const authenticator = new AppPot.LocalAuthenticator(authInfo, conf, ajax);
const log = (msg, level) => {
return new Promise( (resolve, reject)=>{
ajax.post('logs')
.send({
message: '[tpredge]['+macAddr+'] ' + msg,
logLevel: level || 'MONITOR'
})
.end(AppPot.Ajax.end(resolve, reject));
});
};
// ログイン
yield authenticator.login(account.username, account.password);
yield log(message);
})
.catch(error=>{
console.log(error);
if(error.results) {
if(error.results.code == 'ECONNABORTED' && error.results.errno == 'ETIME'){
process.exit(2);
}
}
process.exit(255);
});