Skip to content

This is a little Powershell script that fetch metric's values from NetHASP Monitor

License

Notifications You must be signed in to change notification settings

zbx-sadman/HASP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NetHASP

This is a little Powershell script that fetch metric's values from Sentinel/Aladdin HASP Network Monitor. Tanx to Tor user for HaspMonitor.exe utility.

Actual release 1.2.0

Note if you detect memory leak on your Windows OS when begin using the script - just update the HASP drivers. Aladdin's drivers can be leaks reason.

Note Since release v1.0 NetHASP Miner do not use HaspMonitor.exe to avoid runtime overheads. hsmon.dll wrapper will be compiled on the script's first call. By virtue of certain .NET procedures first run will be longer that other. Keep calm, please.

Note Due hsmon.dll compiled to 32-bit systems, you need to provide 32-bit environment to run all code, that use that DLL. To avoid errors when script is running on 64-bit systems 32-bit instance of PowerShell must be used. It may be placed here: %WINDIR%\SysWOW64\WindowsPowerShell\v1.0\powershell.exe.

Support objects:

  • Server - NetHASP server that can detected with "GET SERVERS" command;
  • Module - NetHASP Module that can detected with "GET MODULES ..." command;
  • Slot - NetHASP Slot that can detected with "GET SLOTS ..." command;
  • Login - NetHASP Login that can detected with "GET LOGINS ..." command.

Actions:

  • Discovery - Make Zabbix's LLD JSON;
  • Get - Get metric of object collection's item;
  • Count - Count collection's items;
  • DoCommand - Do NetHASP Monitîr command that not required connection to server (HELP, VERSION). Command must be specified with -Key parameter.

Zabbix's LLD available to:

  • Server ;
  • Module ;
  • Slot ;
  • Login .

How to use standalone

At First - check value of variable HSMON_LIB_PATH which placed inside .ps1. Choose one - let script search all need files (hsmon.dll, nethasp.ini, wraphsmon.dll) in dir, from where it executed or use fixed path, that you set manually.

Now running of Miner so simple - just use parameters to specify:

  • -Action - what need to do with collection or items;
  • -Object - what will be collected;
  • -Key - "path" to collection item's metric;
  • -ServerID - to point NetHASP server from list;
  • -ModuleID - to make additional objects selecting by Module Address;
  • -SlotID - to make additional objects selecting by Slot;
  • -LoginID - to make additional objects selecting by login Index;
  • -ErrorCode - what must be returned if any process error will be occurs;
  • -ConsoleCP - codepage of Windows console. Need to properly convert output to UTF-8;
  • -DefaultConsoleWidth - to leave default console width and not change it size to CONSOLE_WIDTH (see .ps1 code);
  • -Verbose - to enable verbose messages.

Examples:

# Get output of NetHASP Monitor VERSION command
powershell -NoProfile -ExecutionPolicy "RemoteSigned" -File "nethasp.ps1" -Action "DoCommand" -Key "VERSION" -defaultConsoleWidth

# Make Zabbix's LLD JSON for NetHASP servers
... "nethasp.ps1" -Action "Discovery" -Object "Server" 

# Return number of used licenses on Slot #16 of stuffserver.contoso.com server. If processing error reached - return "-127"  
... "nethasp.ps1" -Action "Get" -Object "Slot" -Key "CURR" -ServerId "stuffserver.contoso.com" -SlotId "16" -ErrorCode "-127"

# Show formatted list of 'Module' object(s) metrics. Verbose messages is enabled. Console width is not changed.
... "nethasp.ps1" -Action "Get" -Object "Module" -defaultConsoleWidth -Verbose

How to use with Zabbix

  1. Just include zbx_hasp.conf to Zabbix Agent config;
  2. Check path to 32-bit PowerShell instance in zbx_hasp.conf and change its if you need;
  3. Put nethasp.ps1, hsmon.dll, nethasp.ini to C:\zabbix\scripts\nethasp dir;
  4. Change NH_SERVER_ADDR into nethasp.ini to yours NetHASP server or enable Broadcast feature;
  5. Make unsigned .ps1 script executable with Set-ExecutionPolicy RemoteSigned;
  6. Set Zabbix Agent's / Server's Timeout to more that 3 sec (may be 10 or 30);
  7. Import template to Zabbix Server;
  8. At first time run script to do any simply request (like -Action DoCommand -Key "HELP" ) to let self-complie NetHASP monitor library wrapper. Its can be get some time;
  9. Enjoy.

Note Do not try import Zabbix v2.4 template to Zabbix pre v2.4. You need to edit .xml file and make some changes at discovery_rule - filter tags area and change # to <> in trigger expressions. I will try to make template to old Zabbix.

Hints

  • NetHASP server can periodically change Server ID. In this case use -ServerId option with alphanumeric server name, that can be known by running script with -Action Get -Object Server options;
  • To see keys, run script without -Key option: ... "nethasp.ps1" -Action "Get" -Object "Object" ;
  • To measure script run time use -Verbose command line switch;
  • Use -ErrorCode options for monitoring systems events/triggers to runtime errors detection;
  • Running the script with PowerShell 3 and above may be require to enable PowerShell 2 compatible mode.

USBHASP

The same that NetHASP Miner, but used for monitoring Sentinel/Aladdin HASP USB license keys, which installed locally or binded with USB/IP.

Actual release 1.2.0

Tested on Windows Server 2008R2 SP1, USB/IP service, Powershell 2.0

Support objects:

  • USBController - "Physical" devices (USB Key, Win32_USBControllerDevice.Antecedent);
  • LogicalDevice - "Logical" devices (HASP Key, Win32_USBControllerDevice.Dependent)

Actions:

  • Discovery - Make Zabbix's LLD JSON;
  • Get - Get metric of object collection item;
  • Count - Count collection items.

How to use standalone

# Make Zabbix's LLD JSON for USB keys
powershell -NoProfile -ExecutionPolicy "RemoteSigned" -File "usbhasp.ps1" -Action "Discovery" -Object "USBController"

# Return number of HASP keys
... "usbhasp.ps1" -Action "Count" -Object "LogicalDevice"

# Show formatted list of 'USBController' object metrics selected by PnPId "USB\VID_0529&PID_0001\1&79F5D87&0&01". 
# Verbose messages is enabled. Note that PNPDeviceID is unique for USB Key, Id - is not.
... "usbhasp.ps1" -Action "Get" -Object "USBController" -PnPDeviceID "USB\VID_0529&PID_0001\1&79F5D87&0&01" -defaultConsoleWidth -Verbose

How to use with Zabbix

  1. Make setting to make unsigned .ps1 scripts executable for all time with powershell.exe -command "Set-ExecutionPolicy RemoteSigned" or for once with -ExecutionPolicy command line option;
  2. Just include zbx_hasp.conf to Zabbix Agent config;
  3. Move usbhasp.ps1 to C:\zabbix\scripts dir;
  4. Set Zabbix Agent's / Server's Timeout to more that 3 sec (may be 10 or 30);
  5. Import template to Zabbix Server;
  6. Enjoy again.

Hints

  • Be sure that you filter LLD to leave only 'HASP' or 'ALADDIN' records;
  • Do not forget to use Zabbix agent's "UnsafeUserParameters=1" option to avoid "ZBX_NOTSUPPORTED: Special characters ... are not allowed in the parameters" error.

About

This is a little Powershell script that fetch metric's values from NetHASP Monitor

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published