Community discussions

MikroTik App
 
dotnetpower
just joined
Topic Author
Posts: 5
Joined: Sat Nov 13, 2010 4:03 pm

Struggeling with reading from Logfile

Thu Oct 16, 2014 5:45 pm

Hi community :)

I struggeling with my dude function and probe.

This is what i like to do:

I create a textfile with Powershell witch contains an Performancecounter value like 56 or 56.3455656

To use this Value i have created the following function:

Name: fhq_value
Code: array_element(execute("GetLog.bat","FIQ.log","C:\\"),1)

If i put this in the Appereance of one of my servers it returns my the value as it should do.

Then i have created a probe:

Name: HighFaxQueue
Type: Function
Agent: Server

Availible: if(fhq_value()>0, 1, -1)
Error: if(fhq_value()<285,"", "ERROR")
Value: fhq_value()
Unit: Faxes

But this did not work. No matter what i put in the input file, the probe reports me anytime "Availible"

Did anybody of you have an idiea where i have done the mistake?

Thank you very much,

Bernd
 
lebowski
Forum Guru
Forum Guru
Posts: 1619
Joined: Wed Aug 27, 2008 5:17 pm

Re: Struggeling with reading from Logfile

Thu Oct 16, 2014 10:44 pm

Availible: if(fhq_value()>0, 1, 0)

is that the fix?
 
dotnetpower
just joined
Topic Author
Posts: 5
Joined: Sat Nov 13, 2010 4:03 pm

Re: Struggeling with reading from Logfile

Fri Oct 17, 2014 10:26 am

Hi,

thank you for your very quick answer.

But unfortunately it did not solve the problem :(

Image
 
lebowski
Forum Guru
Forum Guru
Posts: 1619
Joined: Wed Aug 27, 2008 5:17 pm

Re: Struggeling with reading from Logfile

Fri Oct 17, 2014 4:36 pm

Available is only used to determine if the probe should be installed on a device when using auto discover.
Just put 1 in the available line for now and see if that allows the probe to function.


MAYBE this would work. (execute is very finicky since it is run as "system")
Change the function to return a value or False. Then you will get "False" when the system is down.
Name: fhq_value
Code: if(execute("GetLog.bat","FIQ.log","C:\\"),1),array_element(execute("GetLog.bat","FIQ.log","C:\\"),1),"False")

Then in the available line you can just check that it is not False. (remember this is only for auto discover)
fhq_value()<>"False"
and in the error line you can account for false and give a meaningful down message.
if(fhq_value()<>"False",if(fhq_value() < 285, "", concatenate("Warning: Fax server at Capacity = ", ups_cap())), "Failed read Fax Capacity")

Let us know what you end up with.
Lebowski
 
dotnetpower
just joined
Topic Author
Posts: 5
Joined: Sat Nov 13, 2010 4:03 pm

Re: Struggeling with reading from Logfile

Wed Oct 22, 2014 10:20 am

Hi, thank you for your answer. I belive, there is a problem with the operator in general.

If i put this here in the appereance section of may server:

[if(array(execute("GetLog.bat","FIQ.log","C:\\"))>100, "","False")]

then it stays allwas to false. No matter if the value in the logfile is 95 or 105. Nothing changes if
i change the value in the logfile.

If I change the operator from > to < then nothing appears, even if I change here the operators.....

Any ideas?
 
lebowski
Forum Guru
Forum Guru
Posts: 1619
Joined: Wed Aug 27, 2008 5:17 pm

Re: Struggeling with reading from Logfile

Wed Oct 22, 2014 6:22 pm

First I must say I am sorry that I didn't get my last post correct, there is a typo in the function. Second I am sure this will work.

Create a bat file called getlog.bat there are 2 lines in that file. The program "more" returns the value in fig.log so there is no need to make the execute function more complex.
@echo off
more fiq.log

Create fiq.log and put 95 in it with nothing else, make a function;

Function;
name: getfiq
code: if(array_element(execute("GetLog.bat","","C:\\"),1), array_element(execute("GetLog.bat","","C:\\"),1), "False")

probe;
Name: fique
available: getfiq()<>"False"
error: if(getfiq()<>"False",if(getfiq() < 285, "", concatenate("Warning: Fax server at Capacity = ", getfiq())), "Failed read Fax Capacity")
value: getfiq()

Here is the steps I took to make sure things worked each step of the way.

Put [getfiq()] on a device label and the label shows 0,95,

Since that worked modify the device label to [array_element(getfiq(),1)] and the label shows 95 with out the extra fields.

I moved the array_element into the function to verify that there is still 95 on the label.
getfiq
array_element(execute("GetLog.bat","FIQ.log","C:\\"),1)

So now I want to make it return a value or false. Sorry my previous post had a typo, missing an array_element.
This does put the value of fiq.log on the label or false, delete fiq.log from the disk to test.
getfiq
if(array_element(execute("GetLog.bat","","C:\\"),1), array_element(execute("GetLog.bat","","C:\\"),1), "False")

Now the probe is simple since we are sure we are getting a value or false.
Probe: fique
available: getfiq()<>"False"
error: if(getfiq()<>"False",if(getfiq() < 285, "", concatenate("Warning: Fax server at Capacity = ", getfiq())), "Failed read Fax Capacity")
value: getfiq()

See in the graphic below the device label is updated, the probe is going to fail and send an error and if you delete the log file you will see the failed message.
fique - Probe_2014-10-22_09-16-20.png
Note If the value in fiq.log is 0 the error line of the probe will trigger. To fix this you could modify the function to add 1 to the value then just test for 1 less in the error... This is not tested...
code: if(array_element(execute("GetLog.bat","","C:\\"),1)+1, array_element(execute("GetLog.bat","","C:\\"),1)+1, "False")
error: if(getfiq()<>"False",if(getfiq() < 284, "", concatenate("Warning: Fax server at Capacity = ", getfiq())), "Failed read Fax Capacity")


There ya go :)
lebowski
You do not have the required permissions to view the files attached to this post.
 
dotnetpower
just joined
Topic Author
Posts: 5
Joined: Sat Nov 13, 2010 4:03 pm

Re: Struggeling with reading from Logfile

Thu Oct 23, 2014 5:06 pm

You are my Hero!!! :D

It works, thank you very much for this excellent help :)
 
lebowski
Forum Guru
Forum Guru
Posts: 1619
Joined: Wed Aug 27, 2008 5:17 pm

Re: Struggeling with reading from Logfile

Thu Oct 23, 2014 6:12 pm

Awesome, I just wish I had a use fot it but it goes to show the very real power of the dude and the great ideas behind the design.

Who is online

Users browsing this forum: No registered users and 22 guests