How to debug scripts (?)

Post support questions that relate to the Windows 2003/2000/XP operating systems.

Moderators: Developers, Moderators

Post Reply
User avatar
adrianmarsh
Cacti User
Posts: 437
Joined: Wed Aug 17, 2005 8:51 am
Location: UK

How to debug scripts (?)

Post by adrianmarsh »

Has anyone written (or can provide) a quick summary on the best way to debug the script-calling system that cmd.php/cactid uses?

For example, I'm trying to use the WMI scripts to gather memory info (see other thread). Basically - I think everything is ok. When I run from a command line, I get results back out, but when cactid runs the script it fails. All it tells me is "U".... Is it possible to capture the *actual* script output from that session to a file that I could later examine ??

Maybe this is a new feature request to Cactid ? (sort of like a --debug option to run from the command line).


09/19/2005 12:31:42 PM - CACTID: Poller[0] Host[41] DS[1129] SCRIPT: c:/perl/bin/perl.exe C:/inetpub/wwwroot/cacti/scripts/w32_query_OperatingSystem.pl swodell38.uk-lab.lucent.com get TotalVisibleMemorySize,FreePhysicalMemory,TotalVirtualMemorySize,FreeVirtualMemory, output: U
09/19/2005 12:31:42 PM - CACTID: Poller[0] Host[41] DS[1129] WARNING: Result from SCRIPT not valid. Partial Result: ...
09/19/2005 12:31:42 PM - CACTID: Poller[0] Host[41] ERROR: Empty result [swodell38.uk-lab.lucent.com]: 'c:/perl/bin/perl.exe C:/inetpub/wwwroot/cacti/scripts/w32_query_OperatingSystem.pl swodell38.uk-lab.lucent.com get TotalVisibleMemorySize,FreePhysicalMemory,TotalVirtualMemorySize,FreeVirtualMemory'
09/19/2005 12:31:42 PM - CACTID: Poller[0] Host[41] DEBUG: The POPEN returned the following File Descriptor 9
User avatar
BSOD2600
Cacti Moderator
Posts: 12171
Joined: Sat May 08, 2004 12:44 pm
Location: USA

Post by BSOD2600 »

c:/perl/bin/perl.exe C:/inetpub/wwwroot/cacti/scripts/w32_query_OperatingSystem.pl swodell38.uk-lab.lucent.com get TotalVisibleMemorySize,FreePhysicalMemory,TotalVirtualMemorySize,FreeVirtualMemory,

That IS what cacti ran and failed. Since it works under one user account and fails under the one cacti uses, you have a security problem. Fire up dcomcnfg and add your cactiuser to WMI on the machines you need to poll. Google for WMI security and dcomcnfg to find some guides.
User avatar
adrianmarsh
Cacti User
Posts: 437
Joined: Wed Aug 17, 2005 8:51 am
Location: UK

Post by adrianmarsh »

Hiya,

I was just trying TheWitness guide to running the script server manually. I can't quite see how to get it to run perl scripts. I don't think I've got as far yet for being a perms issue.. see below


C:\>c:/perl/bin/perl.exe C:/inetpub/wwwroot/cacti/scripts/w32_query_OperatingSys
tem.pl swodell38 get TotalVisibleMemorySize,FreePhysicalMemory,TotalVirtualMemor
ySize,FreeVirtualMemory
TotalVisibleMemorySize:129252 FreePhysicalMemory:25772 TotalVirtualMemorySize:46
7324 FreeVirtualMemory:146980

C:\>php c:\inetpub\wwwroot\cacti/script_server.php
PHP Script Server has Started - Parent is cmd
c:/perl/bin/perl.exe C:/inetpub/wwwroot/cacti/scripts/w32_query_OperatingSystem.
pl swodell38.uk-lab.lucent.com get TotalVisibleMemorySize,FreePhysicalMemory,Tot
alVirtualMemorySize,FreeVirtualMemory

Parse error: parse error, unexpected '?' in c:\perl\bin\perl.exe on line 13


I've tried various combinations for calling perl (changing / for \ and trying it without calling perl first etc)..

Still working on it...
User avatar
adrianmarsh
Cacti User
Posts: 437
Joined: Wed Aug 17, 2005 8:51 am
Location: UK

Post by adrianmarsh »

Right.. I think I've got it:

I had to exchange "c:\perl\bin\perl.exe" to just "perl" and then I got the half-expected WMI errors... I've not sure why this works, because c:\perl\bin is the right path.

So then I changed the scheduled task to use a domain-admin account, and increased the timeout to 5000ms. I think now its working.

One minor issue though, is that TheWitness' latest upgrade instructions was to make sure the scheduled task is set to run as "System", which of course I've now changed.... I'm not sure of the impact of that yet..
User avatar
BSOD2600
Cacti Moderator
Posts: 12171
Joined: Sat May 08, 2004 12:44 pm
Location: USA

Post by BSOD2600 »

It seems only he had a problem with the latest version of cacti, which was fixed by running it as SYSTEM. This will NOT work if one needs to poll remote computers with scripts that need user authentication (aka WMI).

Best practice is to create a user account for cacti (either local or domain if plausible). Then add that user to your WMI security. Running cacti under a domain account may work fine, but it's not a good idea for security reasons.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest