Issue when I try to use logging feature

1,046 views
Skip to first unread message

Mohammed Imran

unread,
Mar 17, 2015, 5:34:22 AM3/17/15
to exabgp...@googlegroups.com
Hi Thomas,

We are in the process to use exabgp extensively in our environment.

Need some help in fixing the issue

Basically I have created a script which would announce a flowspec filter and withdraw the route after a period of time.

This functionality works with out any issue. I also wanted to add logging to my script so that this will help us in troubleshooting.

so I used python inbuilt logging module, below is my code snippet


handler = RotatingFileHandler('/opt/flowspec/hello.log', maxBytes=1048576, backupCount=5)

log = logging.getLogger('Flowspec')
log.setLevel(logging.DEBUG)
#handler = logging.FileHandler('/opt/flowspec/hello.log',mode='a',encoding=None,delay=False)
handler.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
handler.setFormatter(formatter)
log.addHandler(handler)


Here is my exabgp script

neighbor 30.1.1.11 {
description "will announce a route until told otherwise";
router-id 30.1.1.2;
local-address 30.1.1.2;
local-as 100;
peer-as 100;

# add and remove a route every 10 second
process service-dynamic {
run /opt/flowspec/FlowHandler1.py;
}
#addbracket
#add_script
}

All the files have executable permissions and I am logged in as superuser to run the script.

But when I run I get the below traceback.If I directly run FlowHandler1.py it works fine.

Traceback (most recent call last):
File "/opt/flowspec/FlowHandler1.py", line 38, in <module>
handler = RotatingFileHandler('/opt/flowspec/hello.log', maxBytes=1048576, backupCount=5)
File "/usr/lib/python2.7/logging/handlers.py", line 118, in __init__
BaseRotatingHandler.__init__(self, filename, mode, encoding, delay)
File "/usr/lib/python2.7/logging/handlers.py", line 65, in __init__
logging.FileHandler.__init__(self, filename, mode, encoding, delay)
File "/usr/lib/python2.7/logging/__init__.py", line 897, in __init__
StreamHandler.__init__(self, self._open())
File "/usr/lib/python2.7/logging/__init__.py", line 916, in _open
stream = open(self.baseFilename, self.mode)
IOError: [Errno 13] Permission denied: '/opt/flowspec/hello.log'

Not sure what is the issue.

Appreciate if you can help me with this.

--Imran

Thomas Mangin

unread,
Mar 17, 2015, 5:39:40 AM3/17/15
to exabgp...@googlegroups.com

Hi Mohammed,
> We are in the process to use exabgp extensively in our environment.
Good luck :-)
The good news is that it has nothing to do with ExaBGP, it is an Unix
permission issue:
You do not have the right to write to this folder, by default ExaBGP
drop permission and becomes nobody:nogroup which must not have write
access to this folder.
Create a new folder, make sure it can be a accessed. Something like this
( not tested ).

mkdir /opt/flowspec/logs
chmod 755 /opt/
chmod 755 /opt/flowspec
chmod 775 /opt/flowspec/log
chown root:nogroup /opt/flowspec/log

and have the hello.log created in the log folder.

Please keep in mind the program MUST not finish (it must be an infinite
loop) and may need to read and write from the STDIN/STDOUT (depending on
the ExaBGP configuration). There is many examples in the ./qa/ folder.

Sincerely,

Thomas

Mohammed Imran

unread,
Mar 17, 2015, 5:43:42 AM3/17/15
to exabgp...@googlegroups.com
Thanks for the quick reply.. appreciate that.

Yes it is in the continuous loop.I will try your suggestion.

--Imran

Mohammed Imran

unread,
Mar 17, 2015, 6:04:10 AM3/17/15
to exabgp...@googlegroups.com
Ok I tried the above still getting same issue

Here are the current permissions

drwxr-xr-x  6 root root   4096 Mar 17 02:42 flowspec
drwxr-xr-x   8 root root    4096 Mar 12 23:02 opt
-rwxr-xr-x 1 root root 0 Mar 17 00:53 hello.log
-rwxrwxr-x 1 root root  294 Mar 17 00:35 exabgp.conf
-rwxrwxr-x 1 root root 4941 Mar 17 02:42 FlowHandler1.py
drwxrwxr-x 2 root root 4096 Mar 17 02:41 logs


Traceback (most recent call last):
  File "/opt/flowspec/FlowHandler1.py", line 38, in <module>
    handler = RotatingFileHandler('/opt/flowspec/logs/hello.log', maxBytes=1048576, backupCount=5)

  File "/usr/lib/python2.7/logging/handlers.py", line 118, in __init__
    BaseRotatingHandler.__init__(self, filename, mode, encoding, delay)
  File "/usr/lib/python2.7/logging/handlers.py", line 65, in __init__
    logging.FileHandler.__init__(self, filename, mode, encoding, delay)
  File "/usr/lib/python2.7/logging/__init__.py", line 897, in __init__
    StreamHandler.__init__(self, self._open())
  File "/usr/lib/python2.7/logging/__init__.py", line 916, in _open
    stream = open(self.baseFilename, self.mode)
IOError: [Errno 13] Permission denied: '/opt/flowspec/logs/hello.log'

Mohammed Imran

unread,
Mar 17, 2015, 6:10:31 AM3/17/15
to exabgp...@googlegroups.com
Sorry it worked my bad..
--imran
Reply all
Reply to author
Forward
0 new messages