Monitor Windows via WMI from Cacti on Linux

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

Moderators: Developers, Moderators

Post Reply
lupick
Posts: 18
Joined: Tue Nov 28, 2006 10:44 am

Monitor Service using WMI

Post by lupick »

Hi

I'm moved a littel step forward,

attached you can find data&graph template to monitor service (running/stopped).

using this query:

select * from Win32_PerfRawData

I can get "State" but it's a string and I don't know how to convert it in a number so that Cacti can create graph

So I've used ProcessId to graph the process id of a service. if it's 0 it means that it's stopped.

Not really elegant but it could works, even if some windows process are using all the same processid (svchost.exe)

Claymen do you have a better solution?!?

Thank you

L.
Attachments
services.zip
(4.21 KiB) Downloaded 324 times
User avatar
claymen
Cacti User
Posts: 259
Joined: Mon Aug 18, 2008 4:30 am
Location: Australia
Contact:

Post by claymen »

There are two options I can think of.

1. Modify wmi.php to have a special case for Win32_Service and parse the Running etc into 0,1,2,3.
2. Use sed or maybe awk to do the replacement of Running into 0 or 1 by adding it into your data input method.


I'd lean towards option 2 as you keep the wmi.php as generic as possible and the modification to use sed to process the result can be done within Cacti.
lupick
Posts: 18
Joined: Tue Nov 28, 2006 10:44 am

Monitor Service State

Post by lupick »

Claymen

I'v finished my template,, as suggested I've added a sed to sobtutute "running" with 1 and Stopped with 0

So now the graph is monitoring the effective service state.
Thak's for your help.

Last question.

I'd like to have the service name somewhere on the graph.

Do you know how to add it to the title without manually write it every time? (something like |host description| )

I've already tried to add the "name" datasource and add it as GPRINT item into graph template.

unfortunally cacti doesn't seems to recognize the string and it expect a number so I've alwasy the value 0 instead of service "Name"

take a look to the attachment

L.
Attachments
services-state.zip
(4.15 KiB) Downloaded 282 times
User avatar
claymen
Cacti User
Posts: 259
Joined: Mon Aug 18, 2008 4:30 am
Location: Australia
Contact:

Post by claymen »

From what I understand the only way to do what you are asking is to write a data query which becomes a little more complex. I've looked into it but then there is already work in the form of the WMI plugin but I've somewhat avoided using plugins due to the fact the architecture itself is not included in the main tree. E.g. I have to merge it in every time a vendor supplied package updates cacti.
bonj87
Cacti User
Posts: 92
Joined: Fri Mar 26, 2010 7:42 am

Post by bonj87 »

can i just use these scripts on a cacti install on a windows box?
lupick
Posts: 18
Joined: Tue Nov 28, 2006 10:44 am

Post by lupick »

bonj87 wrote:can i just use these scripts on a cacti install on a windows box?
i don't tink so...
search on the forum a WMI Plugin for Cacti on windows.


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

Post by claymen »

Nope Linux only mate. I guess you could adapt the graph template side of things but not the data input side of it.
bonj87
Cacti User
Posts: 92
Joined: Fri Mar 26, 2010 7:42 am

Post by bonj87 »

bummer.. its exactly what i was looking for .. dang.. and im not a very good script writer myself.
User avatar
claymen
Cacti User
Posts: 259
Joined: Mon Aug 18, 2008 4:30 am
Location: Australia
Contact:

Post by claymen »

bonj87 wrote:bummer.. its exactly what i was looking for .. dang.. and im not a very good script writer myself.
Linux VM maybe?
bonj87
Cacti User
Posts: 92
Joined: Fri Mar 26, 2010 7:42 am

Post by bonj87 »

nah, i have CACTI running on the windows box and id like it to stay there.. ill have to learn how to make these templates and scripts I guess.
zeroy
Posts: 25
Joined: Wed Jan 25, 2006 8:27 am

Post by zeroy »

I must be utterly stupid ?! From readme with CactiWMI from OP:
5. Create your password file in /etc/cacti as per the format below.
We just invent a filename is that it? Did i miss something? What filename do you give the password file? Thanks in advance.
¬¬ZeRoY¬¬
argon0
Cacti User
Posts: 460
Joined: Fri Mar 12, 2004 1:22 pm

Post by argon0 »

AFAIK, you can call the file anything you want, then in the Cacti Interface you specify which filename to use, per host.
No longer a n00by, probably, by now an 0ldby

Now Head of Technology at RSCH, back to the prickly subject of Monitorring....
zeroy
Posts: 25
Joined: Wed Jan 25, 2006 8:27 am

Post by zeroy »

argon0 wrote:AFAIK, you can call the file anything you want, then in the Cacti Interface you specify which filename to use, per host.
Cheers! I though i was going mad. :o
¬¬ZeRoY¬¬
zeroy
Posts: 25
Joined: Wed Jan 25, 2006 8:27 am

Post by zeroy »

Hi there,

Im using CENTOS 5, running Cacti Version 0.8.7e and install the CactiWMI-0.0.6-RC1. Import all templates ok, installed wmic also. I can run any commands i find on this thread with wmic directly and get results OK but when using any in Cacti it fails with:
CMDPHP: Poller[0] Host[6] DS[149] WARNING: Result from CMD not valid. Partial Result: U
When running a test command directly in bash i get this:

Code: Select all

[root@localhost ~]# /usr/bin/php -q /var/www/cacti/scripts/wmi.php -h '<my_host>' -u '/etc/cacti/cactiwmi.pw' -w 'Win32_ComputerSystem' -n '' -k '' -v '' -c 'PercentProcessorTime'
NTSTATUS: NT code 0xc0041017 - NT code 0xc0041017

Return code non-zero, debug mode enabled!

/usr/bin/wmic --namespace='root\CIMV2' --authentication-file=/etc/cacti/cactiwmi.pw //<my_host> "SELECT PercentProcessorTime FROM Win32_ComputerSystem"
Exec Status: 1

PHP Notice:  Undefined offset:  1 in /var/www/cacti/scripts/wmi.php on line 120
Can someone help? It seems to me that some of the functions like Win32_ComputerSystem arent reconize or something?
¬¬ZeRoY¬¬
User avatar
claymen
Cacti User
Posts: 259
Joined: Mon Aug 18, 2008 4:30 am
Location: Australia
Contact:

Post by claymen »

It looks like it wasn't able to run the WMI query.

What happens when you run the wmic command itself?

Code: Select all

/usr/bin/wmic --namespace='root\CIMV2' --authentication-file=/etc/cacti/cactiwmi.pw //<my_host> "SELECT PercentProcessorTime FROM Win32_ComputerSystem" 
Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests