Got it

Python script to reboot AR129. after loss of PPP.

Created: Sep 15, 2018 16:53:21Latest reply: Nov 2, 2018 09:39:21 1241 5 0 0 0
  Rewarded HiCoins: 0 (problem resolved)

Hi,

 

I would like to utilise OPS to complete a reboot if the router loses PPP for more than 10 mins.

I am new to python so have just started trying to learn what it can do.

 

I was thinking of setting the condition to a protocol state change (up to down) on the dialler/virtual template interface and then execute a timed reboot for 10mins. Then create a second script that monitors the state changing down to up and executing commands to cancel the planned reboot.

 

Other than this being a very crude way of implementing this there is an issue when device tries to regain ppp the dialler/Virtual temp int goes up down in very quick succession and would cause multiple scripts to run within seconds.

 

Is it possible to set the condition as loss of ICMP to a specified IP. for eg, ping x.x.x.x every 150 secs , if I receive 4 time outs consecutively then execute reboot.

 

or

 

Dialler/Virtual temp changes to down wait 10 mins recheck interface state and if still down execute reboot.

 

If you have any python examples of this that would also be very helpful as I’m still learning the ropes.


Thanks in advance

 





  • x
  • convention:

Featured Answers
Finn92
Created Nov 2, 2018 09:01:22

  • x
  • convention:

All Answers
Lewplagoop
Lewplagoop Created Sep 17, 2018 06:54:30

Update:
I think this may be able to be done setting the condition to Log Event this will trigger on PPP up or down.

Then use the environment if _iclog_content = down, then set timed reboot
else
wait 10 secs, cancel timed reboot.

this relies on 2 things
My understanding of the enviroment api is correct
and
the script can not be triggerd again while it is allready in use.

your thoughts?

thanks again
View more
  • x
  • convention:

Sergio93
Sergio93 Created Sep 17, 2018 10:43:04

Hello,

Maybe you can modify somehow pys/wan-ppp.py and input your condition to reboot the router.
http://support.huawei.com/hedex/hdx.do?docid=EDOC1000163385&id=dc_cfg_ops_0036&text=OPS%252520Script%252520List&lang=en
It has to be tested anyway..
View more
  • x
  • convention:

Lewplagoop
Lewplagoop Created Sep 30, 2018 16:31:05

Thanks for the suggestion, I have looked into this but could not find where this is stored on the device.

I tried testing a simple reboot router on lan down for a test and work up from there but I am clearly not understanding something.

my scri

import ops # Import the OPS module.
import sys # Import the sys module.
# Subscription processing function
def ops_condition (o):
ops.interface.ifstat_subscribe(lan_down, 2, Ethernet0/0/0, 1)
# Monitor the changes of lan Ethernet0/0/0 and triggers on down

# Work processing function
def ops_execute (o):
ops.cli.open()
ops.cli.execute(handle, "reboot fast", "y")
ops.cli.close(handle)

# reboot router
return 0

|


this is the error I get when trying to assign it to the script assistant

Error: Found exception in script.
Exception info:
Traceback (most recent call last):
File ".lib/frame.py", line 111, in <module>
ret = m.ops_condition(o)
File "flash:$_user/lewis.py", line 6, in ops_condition
ops.interface.ifstat_subscribe(lan_down, 2, Ethernet0/0/0, 1)
AttributeError: 'module' object has no attribute 'ifstat_subscribe'

Sorry like I said Im brand new to this so learning as I go and cant find enough material online to correct my errors.
View more
  • x
  • convention:

Finn92
Finn92 Created Nov 2, 2018 09:01:22

  • x
  • convention:

chenhui
chenhui Admin Created Nov 2, 2018 09:39:21

Posted by Lewplagoop at 2018-09-30 16:31 Thanks for the suggestion, I have looked into this but could not find where this is stored on the de ...
suggest you check your python code,
from the attributeError,it seems that 'module' object has no attribute 'ifstat_subscribe' which you called this attribute on line 6.
you'd better check source code of 'module' object,or check if you entered the attribute name wrong.Python script to reboot AR129. after loss of PPP.-2793853-1
View more
  • x
  • convention:

Comment

You need to log in to comment to the post Login | Register
Comment

Notice: To protect the legitimate rights and interests of you, the community, and third parties, do not release content that may bring legal risks to all parties, including but are not limited to the following:
  • Politically sensitive content
  • Content concerning pornography, gambling, and drug abuse
  • Content that may disclose or infringe upon others ' commercial secrets, intellectual properties, including trade marks, copyrights, and patents, and personal privacy
Do not share your account and password with others. All operations performed using your account will be regarded as your own actions and all consequences arising therefrom will be borne by you. For details, see " User Agreement."

My Followers

Login and enjoy all the member benefits

Login

Block
Are you sure to block this user?
Users on your blacklist cannot comment on your post,cannot mention you, cannot send you private messages.
Reminder
Please bind your phone number to obtain invitation bonus.