Monitor Windows via WMI from Cacti on Linux

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

Post Reply
User avatar
claymen
Cacti User
Posts: 259
Joined: Mon Aug 18, 2008 4:30 am
Location: Australia
Contact:

Post by claymen »

argon0 wrote:Ok, my security guy said he would prefer it if it used Kerberos, can you run through how I set it up for this? Or is this the default? If it is how does it work?

I.e. how is the client authenticating using kerberos without joining the domain (which, as I understand it, is a requirement of kerberos...)

Argon0
You'll probably need to configure it all up to join the domain. Good luck with that. To be honest it sounds like crying about nothing. If the AD user you are using is setup properly its a non-issue. And really its no less secure than using SNMP. Also keep in mind that cacti itself doesn't just automatically join the domain either, you'd need to set that up to use LDAP and then SSL LDAP which is possibly another headache.

To save yourself a heap of headache this is what you want
* Create your AD user
* Deny it pretty much everything via group policy so that it can only be used to remote WMI (e.g. disabling interactive logon etc, and one would hope you already have something in place for service accounts...)
* Allow it read only access to the WMI root
* Allow it remote execute access to DCOM
* Use group policy to add the user or a group the user is in to the local machines performance monitors group so it can read counters

And that's really it. It will use NTLM by default which is fine for this (and NTLMv2 isn't exactly that bad). If the user is compromised it can't access anything or logon interactively to machines and assuming you haven't used "Domain Users" everywhere to define access you shouldn't have any problems with it accessing file shares it shouldn't.

In all cases your wmi-logins.php will have the credential in plain text. Your more likely going to get someone reading that than someone sniffing it over the wire. And to be honest Cacti doesn't do stuff all input parsing and thus you can easily do all sorts of fun stuff so if security is such an issue you shouldn't be using Cacti at all.
vpl
Posts: 15
Joined: Thu Nov 01, 2007 11:09 pm

Post by vpl »

How did you get this working with Server 2008? I keep getting a 0xc002001b error.
User avatar
claymen
Cacti User
Posts: 259
Joined: Mon Aug 18, 2008 4:30 am
Location: Australia
Contact:

Post by claymen »

vpl wrote:How did you get this working with Server 2008? I keep getting a 0xc002001b error.
It just worked for us, we run with restricted RPC port ranges because we have firewalls between everything but that's it. Any other details to help out?
vpl
Posts: 15
Joined: Thu Nov 01, 2007 11:09 pm

Post by vpl »

I'm trying to get this working first, so I'm running it totally open. No firewalls/routers between the hosts, no firewalls active on them. I run wmic using domain admin credentials (again, I'm just trying to demonstrate it works first).

The polling host is Ubuntu 8.04. I installed the client using apt, which is this one I think.

I even run the command as root.

wmic -U Domain/account%password //192.168.1.2 "select * from Win32_ComputerSystem"
ERROR: WMI query execute.
NTSTATUS: NT code 0xc002001b - NT code 0xc002001b
argon0
Cacti User
Posts: 460
Joined: Fri Mar 12, 2004 1:22 pm

Post by argon0 »

* Allow it read only access to the WMI root
In the wmi security tab - which option is read only?

Off to google it right now...
No longer a n00by, probably, by now an 0ldby

Now Head of Technology at RSCH, back to the prickly subject of Monitorring....
argon0
Cacti User
Posts: 460
Joined: Fri Mar 12, 2004 1:22 pm

Post by argon0 »

To save yourself a heap of headache this is what you want
* Create your AD user
* Deny it pretty much everything via group policy so that it can only be used to remote WMI (e.g. disabling interactive logon etc, and one would hope you already have something in place for service accounts...)
* Allow it read only access to the WMI root
* Allow it remote execute access to DCOM
* Use group policy to add the user or a group the user is in to the local machines performance monitors group so it can read counters
Right, followed all the above and now get this:
/usr/bin/php -q /var/www/html/scripts/wmi.php 10.0.254.6 cacti Win32_PerfFormattedData_PerfOS_Processor PercentProcessorTime

NTSTATUS: NT code 0xc0041003 - NT code 0xc0041003
Tried it on various machines, it works if the account I'm using is in the Local Administrators account, in all cases....
No longer a n00by, probably, by now an 0ldby

Now Head of Technology at RSCH, back to the prickly subject of Monitorring....
outspoken
Posts: 17
Joined: Thu Nov 20, 2008 4:51 pm

Post by outspoken »

Not getting graphs from Disk I/O, looks like a CDEF issue but i'm not sure what the CDEF is supposed to look like for all of these WMI templates. Most of them are broken, how can I get the correct CDEF from the template?


Data Source Debug

Code: Select all

/usr/local/rrdtool-1.2.23/bin/rrdtool create \
/usr/local/apache/www/cacti2/rra/hostname_readbytespersec_1923.rrd \
--step 300  \
DS:WritesPersec:COUNTER:600:0:100000000000 \
DS:ReadsPersec:COUNTER:600:0:100000000000 \
DS:QueueLength:GAUGE:600:0:10000 \
DS:WriteBytesPersec:COUNTER:600:0:100000000000000000 \
DS:ReadBytesPersec:COUNTER:600:0:100000000000000000 \
RRA:AVERAGE:0.5:1:500 \
RRA:AVERAGE:0.5:1:600 \
RRA:AVERAGE:0.5:6:700 \
RRA:AVERAGE:0.5:24:775 \
RRA:AVERAGE:0.5:288:797 \
RRA:MAX:0.5:1:500 \
RRA:MAX:0.5:1:600 \
RRA:MAX:0.5:6:700 \
RRA:MAX:0.5:24:775 \
RRA:MAX:0.5:288:797 \
from log:

Code: Select all

SCRIPT: /usr/bin/php -q /usr/local/apache/www/cacti2/scripts/wmi.php hostname credential 
Win32_PerfRawData_PerfDisk_LogicalDisk DiskWritesPersec,DiskWriteBytesPersec,DiskReadsPersec,
DiskReadBytesPersec,CurrentDiskQueueLength Name C\:, output: CurrentDiskQueueLength:0 
DiskReadBytesPersec:11125206528 DiskReadsPersec:342825 DiskWriteBytesPersec:34422985216 
DiskWritesPersec:3278114
cdef

Code: Select all

cdef=a,b,c
commandline script:

Code: Select all

/usr/bin/php -q /usr/local/apache/www/cacti2/scripts/wmi.php hostname credential Win32_PerfRawData_PerfDisk_LogicalDisk DiskWritesPersec,DiskWriteBytesPersec,DiskReadsPersec,DiskReadBytesPersec,CurrentDiskQueueLength Name C\:

CurrentDiskQueueLength:0 DiskReadBytesPersec:11125230080 DiskReadsPersec:342826 DiskWriteBytesPersec:34429410304 DiskWritesPersec:3278818 Name:C
Graph Debug

Code: Select all

/usr/local/rrdtool-1.2.23/bin/rrdtool graph - \
--imgformat=PNG \
--start=-86400 \
--end=-300 \
--title="ryemsx01 - Disk I/O" \
--base=1000 \
--height=120 \
--width=500 \
--alt-autoscale-max \
--lower-limit=0 \
--vertical-label="operations per/sec" \
--slope-mode \
--font TITLE:8: \
--font AXIS:8: \
--font LEGEND:8: \
--font UNIT:8: \
DEF:a="/usr/local/apache/www/cacti2/rra/hostname_readbytespersec_1923.rrd":ReadsPersec:AVERAGE \
DEF:b="/usr/local/apache/www/cacti2/rra/hostname_readbytespersec_1923.rrd":WritesPersec:AVERAGE \
DEF:c="/usr/local/apache/www/cacti2/rra/hostname_readbytespersec_1923.rrd":QueueLength:AVERAGE \
CDEF:cdefa=a,b,c \
AREA:cdefa#BCBEB3FF:"Total\:"  \
GPRINT:cdefa:LAST:"       Current\:%8.2lf %s"  \
GPRINT:cdefa:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:cdefa:MAX:"Maximum\:%8.2lf %s\n"  \
LINE1:a#FF0000FF:"Read\:"  \
GPRINT:a:LAST:"        Current\:%8.2lf %s"  \
GPRINT:a:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:a:MAX:"Maximum\:%8.2lf %s\n"  \
LINE1:b#002A97FF:"Write\:"  \
GPRINT:b:LAST:"       Current\:%8.2lf %s"  \
GPRINT:b:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:b:MAX:"Maximum\:%8.2lf %s\n"  \
LINE1:c#000000FF:"Queue Length\:"  \
GPRINT:c:LAST:"Current\:%8.2lf %s"  \
GPRINT:c:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:c:MAX:"Maximum\:%8.2lf %s\n"
Last edited by outspoken on Thu Feb 26, 2009 1:42 pm, edited 3 times in total.
argon0
Cacti User
Posts: 460
Joined: Fri Mar 12, 2004 1:22 pm

Post by argon0 »

But now working....

Very minimal access needed - set user as member of Performance Logs Users local group.


Set WMI Properties to have Remote Enable permissions.

Set the Component Services to have Remote activation from the Launch Permissions - edit limits button.

And that was enough....
No longer a n00by, probably, by now an 0ldby

Now Head of Technology at RSCH, back to the prickly subject of Monitorring....
bites
Posts: 5
Joined: Wed Oct 29, 2008 5:55 pm
Contact:

Post by bites »

One problem I found that had me bashing my head against the wall was this:

All graphs for SNMP work no problem ... however SOME of the WMI one wouldn't work ... couldn't figure out why, testing returned

I found this however.

Testing the command locally

Code: Select all

NTSTATUS: NT code 0xc0041010 - NT code 0xc0041010
The code basically means it couldnt find the variable requested.

Running perfmon on the host machine, I could see the variable/table, this was very confusing!

However running perfmon with WMI I couldn't see the variable.
You can confirm this by running:

Code: Select all

perfmon /wmi[code]

Click "Add Counter" and see if the one your trying to graph is listed, more than likely it won't be (if your getting the same error code).

So ... took me a while to find this and I found this via searching for why the SQL stats wouldn't poll.

On the machine being polled run,

[code]wmiadap.exe /f
Now try perfmon with /wmi ...

Variable/table shows .. and graphs now populate.

/reinsert hair into head!

Hope this helps someone :)
User avatar
claymen
Cacti User
Posts: 259
Joined: Mon Aug 18, 2008 4:30 am
Location: Australia
Contact:

Post by claymen »

bites wrote:One problem I found that had me bashing my head against the wall was this:

All graphs for SNMP work no problem ... however SOME of the WMI one wouldn't work ... couldn't figure out why, testing returned

I found this however.

Testing the command locally

Code: Select all

NTSTATUS: NT code 0xc0041010 - NT code 0xc0041010
The code basically means it couldnt find the variable requested.

Running perfmon on the host machine, I could see the variable/table, this was very confusing!

However running perfmon with WMI I couldn't see the variable.
You can confirm this by running:

Code: Select all

perfmon /wmi[code]

Click "Add Counter" and see if the one your trying to graph is listed, more than likely it won't be (if your getting the same error code).

So ... took me a while to find this and I found this via searching for why the SQL stats wouldn't poll.

On the machine being polled run,

[code]wmiadap.exe /f
Now try perfmon with /wmi ...

Variable/table shows .. and graphs now populate.

/reinsert hair into head!

Hope this helps someone :)
That's a common issue and Microsoft document it on the following link.

http://msdn.microsoft.com/en-us/library ... 85%29.aspx

Basically that command parses all the libraries and refreshes the performance monitor classes if they are missing. You can use it to fix the Exchange WMI classes and SQL classes not showing up as well.

Grab a copy of Scriptomatic2 from Microsoft to see what WMI classes are available, if any are missing thats when I tend to run wmiadap /f
User avatar
claymen
Cacti User
Posts: 259
Joined: Mon Aug 18, 2008 4:30 am
Location: Australia
Contact:

Post by claymen »

argon0 wrote:But now working....

Very minimal access needed - set user as member of Performance Logs Users local group.


Set WMI Properties to have Remote Enable permissions.

Set the Component Services to have Remote activation from the Launch Permissions - edit limits button.

And that was enough....
Someone posted a link earlier which went through it but yer once you have the modifications in place a limited user can query it :) It all comes down to permissions as to what they can query. So you can get pretty granular if you really want to.

I would still use group policy to deny that service account interactive login to anything to prevent someone using it to get an actual login on a machine. I know it doesnt solve it cause they could still run stuff remotely but it adds that little bit more annoyance to actually use it. And I would also use group policy to automate setting as many of those settings as you can so that it doesnt need to be done per box :)
Last edited by claymen on Thu Feb 26, 2009 6:54 pm, edited 1 time in total.
User avatar
claymen
Cacti User
Posts: 259
Joined: Mon Aug 18, 2008 4:30 am
Location: Australia
Contact:

Post by claymen »

outspoken wrote: Graph Debug

Code: Select all

/usr/local/rrdtool-1.2.23/bin/rrdtool graph - \
--imgformat=PNG \
--start=-86400 \
--end=-300 \
--title="ryemsx01 - Disk I/O" \
--base=1000 \
--height=120 \
--width=500 \
--alt-autoscale-max \
--lower-limit=0 \
--vertical-label="operations per/sec" \
--slope-mode \
--font TITLE:8: \
--font AXIS:8: \
--font LEGEND:8: \
--font UNIT:8: \
DEF:a="/usr/local/apache/www/cacti2/rra/hostname_readbytespersec_1923.rrd":ReadsPersec:AVERAGE \
DEF:b="/usr/local/apache/www/cacti2/rra/hostname_readbytespersec_1923.rrd":WritesPersec:AVERAGE \
DEF:c="/usr/local/apache/www/cacti2/rra/hostname_readbytespersec_1923.rrd":QueueLength:AVERAGE \
CDEF:cdefa=a,b,c \
AREA:cdefa#BCBEB3FF:"Total\:"  \
GPRINT:cdefa:LAST:"       Current\:%8.2lf %s"  \
GPRINT:cdefa:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:cdefa:MAX:"Maximum\:%8.2lf %s\n"  \
LINE1:a#FF0000FF:"Read\:"  \
GPRINT:a:LAST:"        Current\:%8.2lf %s"  \
GPRINT:a:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:a:MAX:"Maximum\:%8.2lf %s\n"  \
LINE1:b#002A97FF:"Write\:"  \
GPRINT:b:LAST:"       Current\:%8.2lf %s"  \
GPRINT:b:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:b:MAX:"Maximum\:%8.2lf %s\n"  \
LINE1:c#000000FF:"Queue Length\:"  \
GPRINT:c:LAST:"Current\:%8.2lf %s"  \
GPRINT:c:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:c:MAX:"Maximum\:%8.2lf %s\n"
Yer from the looks of things your getting data but the graph is broken because of the CDEF. What version of Cacti are you running? I found this tends to happen when trying to use templates built in 0.8.7b on 0.8.7.

Here is an example of what your debug should look like for a working graph.

Code: Select all

/usr/bin/rrdtool graph - \
--imgformat=PNG \
--start=-86400 \
--end=-300 \
--title="server - Disk I/O - H" \
--base=1000 \
--height=120 \
--width=500 \
--alt-autoscale-max \
--lower-limit=0 \
--vertical-label="Operations Per Sec" \
--slope-mode \
--font TITLE:8: \
--font AXIS:8: \
--font LEGEND:8: \
--font UNIT:8: \
DEF:a="/var/www/cacti/rra/server_19581.rrd":WritesPersec:AVERAGE \
DEF:b="/var/www/cacti/rra/server_19581.rrd":WritesPersec:LAST \
DEF:c="/var/www/cacti/rra/server_19581.rrd":WritesPersec:MIN \
DEF:d="/var/www/cacti/rra/server_19581.rrd":WritesPersec:MAX \
DEF:e="/var/www/cacti/rra/server_19581.rrd":ReadsPersec:AVERAGE \
DEF:f="/var/www/cacti/rra/server_19581.rrd":ReadsPersec:LAST \
DEF:g="/var/www/cacti/rra/server_19581.rrd":ReadsPersec:MIN \
DEF:h="/var/www/cacti/rra/server_19581.rrd":ReadsPersec:MAX \
DEF:i="/var/www/cacti/rra/server_19581.rrd":QueueLength:AVERAGE \
DEF:j="/var/www/cacti/rra/server_19581.rrd":QueueLength:LAST \
DEF:ba="/var/www/cacti/rra/server_19581.rrd":QueueLength:MIN \
DEF:bb="/var/www/cacti/rra/server_19581.rrd":QueueLength:MAX \
CDEF:cdefa=a,e,+ \
CDEF:cdefb=a,e,+ \
CDEF:cdefd=a,e,+ \
AREA:cdefa#BCBEB3FF:"Total\:"  \
GPRINT:cdefb:LAST:"       Current\:%8.2lf %s"  \
GPRINT:cdefa:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:cdefd:MAX:"Maximum\:%8.2lf %s\n"  \
LINE1:e#FF0000FF:"Read\:"  \
GPRINT:f:LAST:"        Current\:%8.2lf %s"  \
GPRINT:e:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:h:MAX:"Maximum\:%8.2lf %s\n"  \
LINE1:a#002A97FF:"Write\:"  \
GPRINT:b:LAST:"       Current\:%8.2lf %s"  \
GPRINT:a:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:d:MAX:"Maximum\:%8.2lf %s\n"  \
LINE1:i#000000FF:"Queue Length\:"  \
GPRINT:j:LAST:"Current\:%8.2lf %s"  \
GPRINT:i:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:bb:MAX:"Maximum\:%8.2lf %s\n" 
See how it automatically defines a heap more data sources for AVERAGE,MIN,MAX,LAST rather than just AVERAGE on yours. Thats what the problem is. To fix it on yours you need to adjust the CDEF to suit only have 3 data sources instead of the 12.

So instead of the CDEF being a,e,+ you will probably want a,b,+

Does that make sense?
bites
Posts: 5
Joined: Wed Oct 29, 2008 5:55 pm
Contact:

Post by bites »

claymen wrote:That's a common issue and Microsoft document it on the following link.

http://msdn.microsoft.com/en-us/library ... 85%29.aspx

Basically that command parses all the libraries and refreshes the performance monitor classes if they are missing. You can use it to fix the Exchange WMI classes and SQL classes not showing up as well.

Grab a copy of Scriptomatic2 from Microsoft to see what WMI classes are available, if any are missing thats when I tend to run wmiadap /f
Yeah common issue doesn't unfortunately mean easily found :)

WMIexplorer shows the same :)
User avatar
claymen
Cacti User
Posts: 259
Joined: Mon Aug 18, 2008 4:30 am
Location: Australia
Contact:

Post by claymen »

bites wrote: Yeah common issue doesn't unfortunately mean easily found :)

WMIexplorer shows the same :)
Haha true, it also doesn't help that Microsoft don't tell you that you need to restart the machine or the WMI service either ;)

Or the complete lack of SQL 2000 WMI documentation... Some vendors (Who will remain anonymous) are just as bad though, implementing WMI classes for monitoring but not documenting what they are. Some of them are common sense but some are just annoying and you have to guess and monitor before you can be sure its what you want.
outspoken
Posts: 17
Joined: Thu Nov 20, 2008 4:51 pm

Post by outspoken »

claymen wrote:
See how it automatically defines a heap more data sources for AVERAGE,MIN,MAX,LAST rather than just AVERAGE on yours. Thats what the problem is. To fix it on yours you need to adjust the CDEF to suit only have 3 data sources instead of the 12.

So instead of the CDEF being a,e,+ you will probably want a,b,+

Does that make sense?
That fixed it, thanks a lot! ;)

I'm using 0.8.7d

I'm also having a problem with some of the Exchange templates. They all seem to be CDEF issues. The strange thing is that I'm not seeing a CDEF listed for it. I think I have to create one for it, so the problem is that my version is not importing the CDEFs properly?

When I go to Graph Management CDEFs I only see:

Code: Select all

WMI - Disk I/O  	
WMI - Disk Used 	
WMI - Memory 	
WMI - Percentage Ratio
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests