Ad Widget

Collapse

Problem with external script calling

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Cenzoooo
    Member
    • Jul 2015
    • 37

    #1

    Problem with external script calling

    Hello,


    I have simple Python script located in /usr/lib/zabbix/externalscripts/

    #!/usr/bin/python2
    import winrm
    import sys

    ip_address = sys.argv[1]
    username = sys.argv[2]
    password = sys.argv[3]
    script_name = sys.argv[4]

    f = open (script_name, 'rb')

    ps_script = f.read()

    s = winrm.Session('http://%s' % ip_address, auth=('%s' % username, '%s' % password), transport='ntlm')

    r = s.run_ps(ps_script)

    if r.status_code != 0:
    print (r.std_err.decode('utf-8'))
    else:
    print (r.std_out.decode('utf-8'))


    This script will execute Powershell Remote command written in PowerShell script also located in /externalscripts/ folder . Example of script execution:

    python testwinrm.py 'ipaddress' 'username' 'password' 'WinSrvBasic.ps'

    When I run this py script in CLI it works great and I get output from Powershell command.
    When I try to run script in frontend I am getting following error:
    2019-01-30 11:18:30 Traceback (most recent call last): File "/usr/lib/zabbix/externalscripts/testwinrm.py", line 10, in <module> f = open (script_name, 'rb') IOError: [Errno 2] No such file or directory: 'WinSrvBasic.ps'
    Any1 have any ideas? So from this error my conclusion is that Zabbix don't recognize that python script is actually using powershell script to execute remote command. How could i fix that? Probably one solution is to have powershell command insite python script, but I want to have 1 global python script which will call dozen's of PowerShell scripts.


    Item configuration:

    Type: External Check
    Key: testwinrm.py["{$HOST.CONN}","{$USER}","{$PASS}","{$PSFILE}"]


    Best Regards
  • Cenzoooo
    Member
    • Jul 2015
    • 37

    #2
    Sorry guys, it is not Zabbix's fault. I needed to write full path to script in my python script: f = open ( "/usr/lib/zabbix/externalscripts/" + script_name, 'rb')

    Comment

    Working...