Submit a ticketCall us
Home > Success Center > Server & Application Monitor (SAM) > SAM - Knowledgebase Articles > Python-based Windows Script Monitor does not return data (SAM)

Python-based Windows Script Monitor does not return data (SAM)

Updated June 22, 2018

Overview

You can use Windows scripting languages to gather metrics and other information that you wish to monitor in SAM. For details, see Configure a Windows Script Monitor and also  

This article describes how a Python-based Windows Script Monitor cannot return data when characters are truncated due to a full buffer that is not flushed.

Here is an example of what may appear in log files when this issue occurs:

Target: 127.0.0.1 
Engine: python 
Script: ==================================================== 
print ("Statistic: 100") 
print ("Message: Things are working as expected") 
Output: ====================================================
Errors: ====================================================
Result: ====================================================
Component Evidence 
Type: DynamicEvidence 
Component Type: WindowsScript 
Actual Outcome: Undefined

 

The default location for SAM logs is c:\ProgramData\SolarWinds\Logs\APM.

Environment

  • SAM 6.6.1 and later
  • Python 3.x
  • Python extensions for Windows (pywin32) versions that match the Python version

Cause 

SAM's Windows Script Monitor use CScript, a front-end application for the Windows Script Host, but does not get data back from the CScript process. If you run CScript manually from the command line (for example, cscript //E:python test.py), output appears. But if you redirect standard output to a file (cscript //E:python test.py > result.txt), no data appears unless you print enough (about 8 KB) characters from the Python script. Any data that exceeds the buffer size will be truncated when the buffer is full again. This occurs because Pywin32 replaces sys.stdout with its own structure, which does not support flushing.

Resolution

Use the script structure shown in the following example:  

# Restore stdout
import sys 
sys.stdout = sys.__stdout__ 

# Your script here
print("Statistic: 100") 
print("Message: Test") 

# Flush stdout
sys.stdout.flush();

 

Last modified

Tags

Classifications

Public