proper last version
This commit is contained in:
parent
9e2ab3ccea
commit
6d468acd6f
1 changed files with 64 additions and 50 deletions
|
|
@ -58,57 +58,71 @@ const logger = log4js.getLogger();
|
||||||
const monitor = log4js.getLogger("monitorLogs");
|
const monitor = log4js.getLogger("monitorLogs");
|
||||||
|
|
||||||
exports.install = function(instance) {
|
exports.install = function(instance) {
|
||||||
process.on('uncaughtException', function (err) {
|
var can = false;
|
||||||
errLogger.error('uncaughtException:', err.message);
|
|
||||||
errLogger.error(err.stack);
|
|
||||||
instance.error(err);
|
|
||||||
});
|
|
||||||
|
|
||||||
instance.on('data', function(data) {
|
process.on('uncaughtException', function (err) {
|
||||||
let str = String(data); // Ensuring data get converted to string
|
errLogger.error('uncaughtException:', err.message);
|
||||||
let message = `{
|
errLogger.error(err.stack);
|
||||||
channel: ${instance.options.slack_channel},
|
instance.error(err);
|
||||||
username: ${instance.options.bot_name},
|
});
|
||||||
icon_emoji: ${instance.options.bot_icon},
|
|
||||||
text: ${str}
|
instance.on('data', function(data) {
|
||||||
}`;
|
if (!can) return;
|
||||||
let headers = {
|
|
||||||
'Content-type': `application/json`,
|
let str = String(data.data); // Ensuring data get converted to string
|
||||||
'Authorization': `Bearer ${instance.options.api_key}`
|
let message = {
|
||||||
|
'channel': instance.options.slack_channel,
|
||||||
|
'username': instance.options.bot_name,
|
||||||
|
'icon_emoji': instance.options.bot_icon,
|
||||||
|
'text': str
|
||||||
|
};
|
||||||
|
let headers = {
|
||||||
|
'Content-type': `application/json`,
|
||||||
|
'Authorization': `Bearer ${instance.options.api_key}`
|
||||||
|
};
|
||||||
|
|
||||||
|
if (F.is4) {
|
||||||
|
instance.send2("is F4");
|
||||||
|
let opt = {
|
||||||
|
'method': 'post',
|
||||||
|
'url': 'https://slack.com/api/chat.postMessage',
|
||||||
|
'headers': headers,
|
||||||
|
'body': JSON.stringify(message),
|
||||||
|
'type': 'json',
|
||||||
|
'callback': function(err, response) {
|
||||||
|
if (response && !err) {
|
||||||
|
var msg = { data: response.body, status: response.status, headers: response.headers, host: response.host, cookies: response.cookies };
|
||||||
|
instance.send2(msg);
|
||||||
|
} else if (err) {
|
||||||
|
errLogger.error('Slack post failed - err:', err, '\n - response was:', response);
|
||||||
|
instance.error(err, response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
instance.send2(opt);
|
||||||
|
REQUEST(opt);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
instance.send2("is NOT F4");
|
||||||
|
|
||||||
|
U.request('https://slack.com/api/chat.postMessage', ['json', 'post'], message, function(err, data, status, headers, host) {
|
||||||
|
if (response && !err) {
|
||||||
|
response.data = { data: data, status: status, headers: headers, host: host };
|
||||||
|
instance.send2(response);
|
||||||
|
} else if (err) {
|
||||||
|
errLogger.error('Slack post failed - err:', err, '\n - response was:', response);
|
||||||
|
instance.error(err, response);
|
||||||
|
}
|
||||||
|
}, null, headers);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
instance.reconfigure = function() {
|
||||||
|
var options = instance.options;
|
||||||
|
can = options.slack_channel && options.bot_name && options.bot_icon && options.api_key ? true : false;
|
||||||
|
instance.status(can ? '' : 'Not configured', can ? undefined : 'red');
|
||||||
};
|
};
|
||||||
|
|
||||||
if (F.is4) {
|
instance.on('options', instance.reconfigure);
|
||||||
let opt = {
|
instance.reconfigure();
|
||||||
'method': 'post',
|
|
||||||
'url': 'https://slack.com/api/chat.postMessage',
|
|
||||||
'headers': headers,
|
|
||||||
'cookies': null,
|
|
||||||
'body': JSON.stringify(message),
|
|
||||||
'type': 'json',
|
|
||||||
'callback': function(err, response) {
|
|
||||||
if (response && !err) {
|
|
||||||
var msg = { data: response.body, status: response.status, headers: response.headers, host: response.host, cookies: response.cookies };
|
|
||||||
instance.send2(msg);
|
|
||||||
} else if (err)
|
|
||||||
errLogger.error('Slack post failed - err:', err, '\n - response was:', response);
|
|
||||||
instance.error(err, response);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
REQUEST(opt);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
U.request('https://slack.com/api/chat.postMessage', ['json', 'post'], JSON.stringify(message), function(err, data, status, headers, host) {
|
|
||||||
console.log("err: ", err);
|
|
||||||
console.log("resp: ", response);
|
|
||||||
if (response && !err) {
|
|
||||||
response.data = { data: data, status: status, headers: headers, host: host };
|
|
||||||
instance.send2(response);
|
|
||||||
} else if (err) {
|
|
||||||
errLogger.error('Slack post failed - err:', err, '\n - response was:', response);
|
|
||||||
instance.error(err, response);
|
|
||||||
}
|
|
||||||
}, null, headers);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue