Ad Widget

Collapse

[ZBX 2.2] powershell & system.run

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eljibe
    Member
    • Apr 2014
    • 31

    #1

    [ZBX 2.2] powershell & system.run

    I'm trying to monitor a log file.
    The host through which I access it is a "Cluster Access Point". Which means I have an agent installed with this configuration:
    Code:
    Hostname=WindowsClusterNode
    And the host, in the Zabbix GUI, is named WindowsClusterAccessPoint.
    So no possibilities to use the builtin logfile monitor of the agent.
    So I'm trying this, in powershell:
    count the number of occurences of a string in a file.
    From the CMD, directly on the machine, I can achieve it like this:
    Code:
    C:\Users\me>powershell -Command "$f=Select-String -path d:\jbw\liste.txt -pattern 301 -allmatches; $f.count"
    1658
    I can also make it work properly using a more complex pattern:
    Code:
    C:\Users\me>powershell -Command "$f=Select-String -path d:\jbw\liste.txt -pattern "301, party" -allmatches; $f.count
    1658
    Using this with zabbix_get, it works:
    Code:
    [root@ZBXSRVR]# /opt/zabxagent/bin/zabbix_get -s ZBXHOST -k system.run["powershell.exe -Command \"\$f=Select-String -path d:\jbw\liste.txt -Pattern 301 -AllMatches; \$f.count\""]
    1658
    BUT if I try this with a more complex pattern, I get this:
    Code:
    [root@ZBXSRVR]# /opt/zabxagent/bin/zabbix_get -s ZBXHOST -k system.run["powershell.exe -Command \"\$f=Select-String -path d:\jbw\liste.txt -Pattern \"301, Called party identification not known\" -AllMatches; \$f.count\""]
    ZBX_NOTSUPPORTED
    I have tried using a variable, with no more success.
    Code:
    [root@ZBXSRVR]# pattern="301, Called party identification not known"
    [root@ZBXSRVR]# /opt/zabxagent/bin/zabbix_get -s ZBXHOST -k system.run["powershell.exe -Command \"\$f=Select-String -path d:\jbw\liste.txt -Pattern ${pattern} -AllMatches; \$f.count\""]
    ZBX_NOTSUPPORTED
    [root@ZBXSRVR]# /opt/zabxagent/bin/zabbix_get -s ZBXHOST -k system.run["powershell.exe -Command \"\$f=Select-String -path d:\jbw\liste.txt -Pattern \"${pattern}\" -AllMatches; \$f.count\""]
    ZBX_NOTSUPPORTED
    I am running out of ideas.

    My file looks like this:
    Code:
    random line
    301, Called party identification not known
    301, Called party identification not known
    another random line
    yet another random line
    another random line
    301, Called party identification not known
    if anyone had an idea, I'd gladly take it.
Working...