Tera Term Language: wait doesn't wait for timeout to end - timeout

I'm trying to write a macro to speed up the setting up of a test.
What I have to do is sending a bunch of config commands to my board, and wait for a 'ok' after each one. The last command is the one that starts the test, and after that I want to wait up to 30 seconds for a certain answer. The problem is that even if I set up a timeout, all commands are sent one after another without waiting for the timeout and the test ends as soon as it starts. Am I missing something?
Here is my code:
send 'command 1'
timeout = 5 ;timeout set to 5 seconds
wait 'ok'
send 'command 2'
timeout = 5 ;timeout set to 5 seconds
wait 'ok'
send 'command 3'
timeout = 5 ;timeout set to 5 seconds
wait 'ok'
send 'command 4'
timeout = 5 ;timeout set to 5 seconds
wait 'ok'
send 'command 5'
timeout = 5 ;timeout set to 5 seconds
wait 'ok'
send 'command 6'
timeout = 5 ;timeout set to 5 seconds
wait 'ok'
send 'test start'
timeout = 30 ;timeout set to 30 seconds
wait 'the response I want'
if result = 1 goto pass
if result = 0 goto fail

Stumbled over your question while looking for a different issue.
Timeout is used to say "If thing has not been done in X time, continue" and only needs to be set once. You also want to set it before you send your commands.
In your case it would be
Timeout = 5
Send 'Command'
Wait 'OK'
Send 'Command'
Wait 'OK'
Timeout = 30
Send 'Command'
Wait 'OK'
You might also want to add a slight pause between them with MPause to keep them from stumbling over each other like old modems tend to do.
Send 'Command'
Wait 'OK'
MPause 50
Send 'Command'
Wait 'OK'
Depending on what your doing it might also be worth changing the Sends and Waits to SendLn and WaitLn, these will send a new line with the commands and wait for a response with a new line, and it's pretty common.
Warning though, TeraTerm is a bit of a buggy mess and is a bit limited. If you can use a real language I'd do so.

Related

While loop timeout

I am trying to pause my code if it has taken less time to run than 1 minute. (then continue to run the rest of the code after that minute has passed). However it only waits for around 30 seconds, so it seems to be timing out. Is this the general behaviour?
I currently have this:
minumum_code_run_time = Time.zone.now + 1.minute
# run code
while Time.zone.now < minimum_code_run_time
end
# carry on with rest of code

How to make Postman/Newman to fail a test after certain time has passed?

So, in my collection I have about ten requests, with the last two being:
/Wait 10 seconds
/Check Complete
The first makes a call to the postman's echo (delay by 10 seconds) and the second is the call to my system to check for the status complete. Now, if status is unavailable I wait another 10s:
postman.setNextRequest("Wait 10 seconds");
The complete status on my system can appear in a minute or so. Now, as one can see - it is an infinite loop if something goes wrong with the system and status is never complete. Is there a way in postman/newman test to fail a test if it has been going for more than 2 minutes, for example.
Additionally, this will be executed in jenkins with command line, so I am not really looking into postman settings or delays between requests in the runner.
you may have a look to newman options here : https://www.npmjs.com/package/newman#newman-run-collection-file-source-options. The interesting option is
--timeout-request : it will surely fulfill your need.
In Postman itself, you may test the responseTime. I recall that there is a snippet, on the right part, which looks like this:
tests["Response time is less than 200ms"] = responseTime < 200;
and which could help you as the test fails if response does not occur within the requested time.
Alexandre
If you are going to be using Jenkins pipeline you can use the timeout step to cause long running jobs to result in failure, here's on for 2 mins.
timeout(120) {
node {
sh 'newman command'
}
}
Check out the "Pipeline Syntax" editor in Jenkins to generated your code block and look for other useful functions.

How to get sidekiq retry_count from inside a job

I am trying to send an alert every time retry_count of a sidekiq job reaches 5(to warn an engineer to check why the worker is failing) and then continued being retried as usual.
Is there a way to get the retry count for a particular job from inside the job?
I could just use:
sidekiq_retry_in do |count|
(warn engineer here)
10 * (count + 1) # (i.e. 10, 20, 30, 40)
end
and send a message from in there, but I think its a bit of a hack.
Any ideas? googling didn't surface any results.
There is no way to get the retry count from within the job, by design.

Multiple times trigger generation in Zabbix

I am new to zabbix. I have a basic requirement of monitoring occurrence of different log messages using zabbix. Say, when there is a log message "server starting", zabbix should show that alert. The idea is that if the server (re)starts 10 times in last 10 minutes, the zabbix dashboard (or at any other place) should display that 10 times.
I have done the following for that :
Created an item under template MyTemplate:
Type : Zabbix Agent (Active)
key : log[/opt/mylog/logs/abc.log,server starting]
Type of information : Log
Update Interval (in sec) : 30
Created a trigger with expression :
{MyTemplate:log[/opt/mylog/logs/abc.log,server
starting].logeventid(1)}=0
With logeventid(1), I am seeing that the alert (trigger) is getting generated only once. It appears only once in the Dashboard --> Last 20 issues. If I go to Monitoring --> Trigger, I see the alert only once, although the log files have 10 entries of the message "server starting" (server restarted 10 times).
Then I set the trigger to following :
{MyTemplate:log[/opt/mylog/logs/abc.log,server
starting].nodata(300)}=0
Now, at Monitoring --> Trigger, I see the alert (trigger) 10 times, but, from the Dashboard --> Last 20 issues it vanishes just after 300 seconds.
My questions are :
What should be the trigger function, I should use? I want to see 10 alerts in zabbix if the same message appears 10 times in the log file within a period of time.
With nodata(300), why does the alert vanish after 300 sec?
Is it ok if I use 30 minutes instead of 300 seconds as an argument of nodata()?
Function logeventid() is normally used for Windows and VMware event logs. In this case, it should probably not be used and it is suspicious that it fires, which might indicate a bug in Zabbix.
Anyway, you can check "Multiple PROBLEM events generation" box in trigger configuration and the trigger will generate a new PROBLEM event every time the condition is true, regardless of its previous value. Instead of logeventid(), you can try using a function that is always true, for instance, strlen()>0.
If you wish the trigger to go into OK state after some time, say, 10 minutes, you can add nodata(10m). Then your trigger will look like this:
{MyTemplate:log[/opt/mylog/logs/abc.log,server starting].strlen()}>0 and
{MyTemplate:log[/opt/mylog/logs/abc.log,server starting].nodata(10m)}=0

Net-ssh timeout for execution?

In my application I want to terminate the exec! command of my SSH connection after a specified amount of time.
I found the :timeout for the Net::SSH.start command but following the documentation this is only for the initial connection. Is there something equivalent for the exec command?
My first guess would be not using exec! as this will wait until the command is finished but using exec and surround the call with a loop that checks the execution status with every iteration and fails after the given amount of time.
Something like this, if I understood the documentation correctly:
server = NET::SSH.start(...)
server.exec("some command")
start_time = Time.now
terminate_calculation = false
trap("TIME") { terminate_calculation = ((Time.now - start_time) > 60) }
ssh.loop(0.1) { not terminate_calculation }
However this seems dirty to me. I expect something like server.exec("some command" { :timeout=>60}). Maybe there is some built in function for achieving this functionality?
I am not sure if this would actually work in a SSH context but Ruby itself has a timeout method:
server = NET::SSH.start ...
timeout 60 do
server.exec! "some command"
end
This would raise Timeout::Error after 60 seconds. Check out the docs.
I don't think there's a native way to do it in net/ssh. See the code, there's no additional parameter for that option.
One way would be to handle timeouts in the command you call - see this answer on Unix & Linux SE.
I think your way is better, as you don't introduce external dependencies in the systems you connect to.
Another solution is to set ConnectTimeout option in OpenSSH configuration files (~/.ssh/config, /etc/ssh_config, ...)
Check more info in
https://github.com/net-ssh/net-ssh/blob/master/lib/net/ssh/config.rb
what I did is have a thread that's doing the event handling. Then I loop for a defined number of seconds until channel closed.If after these seconds pass, the channel is still open, then close it and continue execution.

Resources