Monitor Windows Service stats from Linux

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

Moderators: Developers, Moderators

Post Reply
User avatar
TheWitness
Developer
Posts: 17007
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Re: Monitor Windows Service stats from Linux

Post by TheWitness »

Goto line 600 in the tools and try changing the following:

Code: Select all

new COM('WbemScripting.SWebLocator');
to

Code: Select all

new COM("ADODB.Connection");
If that works, it might have to be repeated in another location too.
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of dozens of Cacti plugins and customization's. Advocate of LAMP, MariaDB, IBM Spectrum LSF and the world of batch. Creator of IBM Spectrum RTM, author of quite a bit of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Percona Device Packages (no support)
Interesting Device Packages


For those wondering, I'm still here, but lost in the shadows. Yearning for less bugs. Who want's a Cacti 1.3/2.0? Streams anyone?
User avatar
TheWitness
Developer
Posts: 17007
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Re: Monitor Windows Service stats from Linux

Post by TheWitness »

You will have to dig deeper to get this one worked out on Windows. Here is a good example of what works:

https://www.php.net/manual/en/class.com.php

Look at example2 there.

1) Connect to the right source
2) The $wmic lines need to be replaced by what is in the example (sorry about that, just two lines)
3) Use the Exec() method per example2 and not ExecQuery() (as it does not exist in the COM class :))
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of dozens of Cacti plugins and customization's. Advocate of LAMP, MariaDB, IBM Spectrum LSF and the world of batch. Creator of IBM Spectrum RTM, author of quite a bit of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Percona Device Packages (no support)
Interesting Device Packages


For those wondering, I'm still here, but lost in the shadows. Yearning for less bugs. Who want's a Cacti 1.3/2.0? Streams anyone?
mrossTTX
Cacti User
Posts: 114
Joined: Wed Dec 07, 2022 12:49 pm

Re: Monitor Windows Service stats from Linux

Post by mrossTTX »

TheWitness wrote: Tue Jan 03, 2023 1:29 pm Goto line 600 in the tools and try changing the following:

Code: Select all

new COM('WbemScripting.SWebLocator');
to

Code: Select all

new COM("ADODB.Connection");
If that works, it might have to be repeated in another location too.
now it shows
2023-01-03 12:46:37 - CMDPHP PHP ERROR Backtrace: (CactiShutdownHandler())
2023-01-03 12:46:37 - ERROR PHP ERROR: Uncaught com_exception: <b>Source:</b> ADODB.Connection<br/><b>Description:</b> Operation is not allowed when the object is closed. in C:\inetpub\wwwroot\cacti\plugins\wmi\wmi_tools.php:601 Stack trace: #0 C:\inetpub\wwwroot\cacti\plugins\wmi\wmi_tools.php(601): com->ConnectServer() #1 C:\inetpub\wwwroot\cacti\plugins\wmi\wmi_tools.php(36): walk_host() #2 {main} thrown in file: C:\inetpub\wwwroot\cacti\plugins\wmi\wmi_tools.php on line: 601
User avatar
TheWitness
Developer
Posts: 17007
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Re: Monitor Windows Service stats from Linux

Post by TheWitness »

Show me those three revised lines of code...
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of dozens of Cacti plugins and customization's. Advocate of LAMP, MariaDB, IBM Spectrum LSF and the world of batch. Creator of IBM Spectrum RTM, author of quite a bit of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Percona Device Packages (no support)
Interesting Device Packages


For those wondering, I'm still here, but lost in the shadows. Yearning for less bugs. Who want's a Cacti 1.3/2.0? Streams anyone?
mrossTTX
Cacti User
Posts: 114
Joined: Wed Dec 07, 2022 12:49 pm

Re: Monitor Windows Service stats from Linux

Post by mrossTTX »

lines 600 to 604
// Windows version
$wmi = new COM("ADODB.Connection");
$wmic = $wmi->ConnectServer($host, $namespace, $username, $password);
$wmic->Security_->ImpersonationLevel = 3;

$data = $wmic->Exec($command);
User avatar
TheWitness
Developer
Posts: 17007
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Re: Monitor Windows Service stats from Linux

Post by TheWitness »

Go back and look at example 2, ConnectServer() is not a supported COM function. You need to simply use the correct function. For one, I can not get my Windows 10 Pro WMI to work any more. Microsoft pisses me off how they continually break things and make firewall rule changes without my consent.
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of dozens of Cacti plugins and customization's. Advocate of LAMP, MariaDB, IBM Spectrum LSF and the world of batch. Creator of IBM Spectrum RTM, author of quite a bit of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Percona Device Packages (no support)
Interesting Device Packages


For those wondering, I'm still here, but lost in the shadows. Yearning for less bugs. Who want's a Cacti 1.3/2.0? Streams anyone?
mrossTTX
Cacti User
Posts: 114
Joined: Wed Dec 07, 2022 12:49 pm

Re: Monitor Windows Service stats from Linux

Post by mrossTTX »

thanks for the info!
ill try to troubleshoot this.
i changed that to just "open" and the error i see now is this (i probably have more work to do , but this is where I am at right now)
2023-01-05 09:24:40 - CMDPHP PHP ERROR Backtrace: (CactiShutdownHandler())
2023-01-05 09:24:40 - ERROR PHP ERROR: Uncaught com_exception: <b>Source:</b> Provider<br/><b>Description:</b> Type mismatch. in C:\inetpub\wwwroot\cacti\plugins\wmi\wmi_tools.php:601 Stack trace: #0 C:\inetpub\wwwroot\cacti\plugins\wmi\wmi_tools.php(601): com->Open() #1 C:\inetpub\wwwroot\cacti\plugins\wmi\wmi_tools.php(36): walk_host() #2 {main} thrown in file: C:\inetpub\wwwroot\cacti\plugins\wmi\wmi_tools.php on line: 601

line 601 now reads as
$wmic = $wmi->Open($host, $namespace, $username, $password);
User avatar
TheWitness
Developer
Posts: 17007
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Re: Monitor Windows Service stats from Linux

Post by TheWitness »

Yea, but again, I don't think you are using the correct syntax.
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of dozens of Cacti plugins and customization's. Advocate of LAMP, MariaDB, IBM Spectrum LSF and the world of batch. Creator of IBM Spectrum RTM, author of quite a bit of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Percona Device Packages (no support)
Interesting Device Packages


For those wondering, I'm still here, but lost in the shadows. Yearning for less bugs. Who want's a Cacti 1.3/2.0? Streams anyone?
User avatar
TheWitness
Developer
Posts: 17007
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Re: Monitor Windows Service stats from Linux

Post by TheWitness »

Can you see the difference?

Code: Select all

$conn->Open("Provider=SQLOLEDB; Data Source=localhost;
Initial Catalog=database; User ID=user; Password=password");
This might work better:

Code: Select all

$wmic = $wmi->Open("Provider=SQLOLEDB; Data Source=$host;
Initial Catalog=database; User ID=$username; Password=$passowrd");
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of dozens of Cacti plugins and customization's. Advocate of LAMP, MariaDB, IBM Spectrum LSF and the world of batch. Creator of IBM Spectrum RTM, author of quite a bit of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Percona Device Packages (no support)
Interesting Device Packages


For those wondering, I'm still here, but lost in the shadows. Yearning for less bugs. Who want's a Cacti 1.3/2.0? Streams anyone?
mrossTTX
Cacti User
Posts: 114
Joined: Wed Dec 07, 2022 12:49 pm

Re: Monitor Windows Service stats from Linux

Post by mrossTTX »

ahhh ok.
Mammoth
Posts: 1
Joined: Sun Mar 03, 2024 1:30 pm

Re: Monitor Windows Service stats from Linux

Post by Mammoth »

TheWitness wrote: Tue Jan 03, 2023 1:22 pm Okay, I never tested from a Windows server to a Windows server. So, I'm not surprised this is not working. Should work from Linux to Windows though.

If you know anything about PHP you might be able to do some debugging to fix this. If you do, a Pull request would be appreciated at the GitHub location.

It's likely an escaping issue associated the the darn backslashes.
My introduction to cacti and the first program .PHP

Code: Select all

    {
			// Windows version
		
			$KodeWin = 'windows-1251';     //!!!!!!!!!!!!!!!!!!!!!!!!
						
			$namespace = preg_replace('~\\\+~', '\\', $namespace);
			$username = iconv('utf-8', $KodeWin, preg_replace('~\\\+~', '\\', $username));	
			$password = iconv('utf-8', $KodeWin, $password);	
			
			$wmi  = new COM('WbemScripting.SWbemLocator');

			if (($wmic = $wmi->ConnectServer($host, $namespace, $username, $password)) !== false) {;
				$wmic->Security_->ImpersonationLevel = 3;
				$wmicdata = $wmic->ExecQuery($command);
				
				
				print "<table style='width:100%'><tr><td class='even'>";
				$indexes = array();		
				
				preg_match('~SELECT (.*?) FROM (.*?)(?: WITHIN| WHERE|\z)~si', $command, $match_class);
					$class   = trim($match_class[2]);
				if($match_class[1] == '*'){ 
					$wmiClass  = new COM('winmgmts:'.$namespace.':'.$class);	
					foreach ($wmiClass->Properties_ as $var) 
						array_push($indexes, $var->Name);					
					}
				else  //{				
					foreach(explode(',', $match_class[1]) as $k=>$v)
						array_push($indexes, trim($v));	
				//}
//				print "<h4>" . __('WMI Query Results for Device: %s, Class: %s, Columns: %s, Rows: %s', $host, $class, sizeof($indexes), sizeof($data), 'wmi') . "</h4>";
				print "<h4>" . __('WMI Query Results for Device: %s, Class: %s, Columns: %s, Rows: %s', $host, $class, sizeof($indexes), $wmicdata->Count, 'wmi') . "</h4>";
				print "<p>" . __('Showing columns and first one or two rows of data.', 'wmi') . "</p>";
				print "</table>";
				print "<table style='width:100%'>";
	
				$i = 1;
				foreach ($wmicdata as  $index ) {
					foreach ($indexes as $var) {	
						$peremennaia = $var;
						form_alternate_row('line' . $peremennaia, true);
						if(is_int($index->$peremennaia))
							$index_data =  $index->$peremennaia;	
						elseif(is_bool($index->$peremennaia)) //{
							if(($index->$peremennaia) == '')
								$index_data = 0;	
							else
								$index_data = $index->$peremennaia;	
						//}
						elseif(is_string($index->$peremennaia)) 
							$index_data = iconv($KodeWin,'utf-8',$index->$peremennaia);	
						else
							$index_data = 'Array Or Null';
						print "<td style='font-weight:bold;'>" . $peremennaia . "</td><td>" . $index_data . "</td>";			
					}
					form_end_row();
					if (($i += 1) > 2 )
						break;	
				}
				print "</table>";
			} else 
				print $wmi->error;
		}

I'm young at cacti and I don't understand a lot. I need a sample that should be printed when running the script with the query 'SELECT * FROM Win32_Process'
Attachments
wmi_tools.php.txt
(22.28 KiB) Downloaded 56 times
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests