Last active
December 8, 2017 19:12
-
-
Save nomoney4me/10ac4d689cb00c084fa8dddc3b1956a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('dotenv').config() | |
const Promise = require('bluebird') | |
, WmiClient = require('wmi-client') | |
var servers = [ | |
{ host:'10.0.10.95', name:'server1', username:process.env.ad_user, password:process.env.ad_pass }, | |
{ host:'10.0.10.10', name:'server2', username:process.env.ad_user, password:process.env.ad_pass } | |
] | |
function connectToServers() { | |
Promise.map(servers, (server) => { | |
var wmiOptions = { | |
host:server.host, | |
username:server.username, | |
password:server.password | |
} | |
server.wmi = Promise.promisifyAll(new WmiClient(wmiOptions)); | |
}) | |
} | |
/* this will be repeating every 5s */ | |
function getWmiData() { | |
Promise.map(servers, (server)=> { | |
const data = getWMI(server.wmi) | |
console.log(data) | |
}) | |
} | |
/* wmi queries functions */ | |
async function getWMI(wmi) { | |
var osVersion = await wmi.queryAsync('SELECT SerialNumber,Caption,Version FROM Win32_OperatingSystem') | |
var services = await wmi.queryAsync('select Caption, Status, Started, ProcessId, DisplayName, Name, PathName from Win32_Service') | |
return {osVersion, services} | |
} | |
Promise.try(() => { | |
connectToServers() | |
}).then(() => { | |
getWmiData() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment