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:
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:
I can also make it work properly using a more complex pattern:
Using this with zabbix_get, it works:
BUT if I try this with a more complex pattern, I get this:
I have tried using a variable, with no more success.
I am running out of ideas.
My file looks like this:
if anyone had an idea, I'd gladly take it.
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
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
Code:
C:\Users\me>powershell -Command "$f=Select-String -path d:\jbw\liste.txt -pattern "301, party" -allmatches; $f.count 1658
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
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
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
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