2017-12-22 22:10:38 +00:00
|
|
|
const os = require('os');
|
2022-05-03 19:57:22 +00:00
|
|
|
const { JSONPath } = require('jsonpath-plus');
|
2017-12-22 22:10:38 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
const FILTERABLE = ['userInfo', 'cpus'];
|
2017-12-22 22:10:38 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
module.exports.templateTags = [
|
|
|
|
{
|
|
|
|
displayName: 'OS',
|
|
|
|
name: 'os',
|
|
|
|
description: 'get OS info',
|
|
|
|
args: [
|
|
|
|
{
|
|
|
|
displayName: 'Function',
|
|
|
|
type: 'enum',
|
|
|
|
options: [
|
|
|
|
{ displayName: 'arch', value: 'arch' },
|
|
|
|
{ displayName: 'cpus', value: 'cpus' },
|
|
|
|
{ displayName: 'freemem', value: 'freemem' },
|
|
|
|
{ displayName: 'hostname', value: 'hostname' },
|
|
|
|
{ displayName: 'platform', value: 'platform' },
|
|
|
|
{ displayName: 'release', value: 'release' },
|
2018-12-12 17:36:11 +00:00
|
|
|
{ displayName: 'userInfo', value: 'userInfo' },
|
|
|
|
],
|
2018-06-25 17:42:50 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'JSONPath Filter',
|
2018-10-17 16:42:33 +00:00
|
|
|
help: 'Some OS functions return objects. Use JSONPath queries to extract desired values.',
|
2018-06-25 17:42:50 +00:00
|
|
|
hide: args => !FILTERABLE.includes(args[0].value),
|
2018-12-12 17:36:11 +00:00
|
|
|
type: 'string',
|
|
|
|
},
|
2018-06-25 17:42:50 +00:00
|
|
|
],
|
|
|
|
run(context, fnName, filter) {
|
|
|
|
let value = os[fnName]();
|
2017-12-22 22:10:38 +00:00
|
|
|
|
2022-05-03 19:57:22 +00:00
|
|
|
if (JSONPath && FILTERABLE.includes(fnName)) {
|
2018-06-25 17:42:50 +00:00
|
|
|
try {
|
2022-05-03 19:57:22 +00:00
|
|
|
value = JSONPath({ json: value, path: filter })[0];
|
2018-06-25 17:42:50 +00:00
|
|
|
} catch (err) {}
|
2017-12-22 22:10:38 +00:00
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
if (typeof value !== 'string') {
|
|
|
|
return JSON.stringify(value);
|
|
|
|
} else {
|
|
|
|
return value;
|
|
|
|
}
|
2018-12-12 17:36:11 +00:00
|
|
|
},
|
|
|
|
},
|
2018-06-25 17:42:50 +00:00
|
|
|
];
|