etingof / snmpfwd

SNMP Proxy Forwarder
http://snmplabs.com/snmpfwd/
BSD 2-Clause "Simplified" License
67 stars 18 forks source link

Running snmpfwd-server in Windows #39

Open JorgeJuanTel opened 5 years ago

JorgeJuanTel commented 5 years ago

Hi

I'm trying to run snmpfwd-server in Windows but when I execute it in a console window nothing happens. No matter what parameters I put, it does not do anything (except the version and help parameters that do work) .

I'm using the example SNMPv3 to SNMPv1 proxy server configuration file. This file is located in the directory "c:\tmp". In the next example, I run the command three times. The first time to check the script printing the version. The second and third time, passing the configuration file with a relative path or with an absolute path.

C:\tmp>snmpfwd-server.py --version SNMP Proxy Forwarder version 0.4.4, written by Ilya Etingof etingof@gmail.com Using foundation libraries: pysnmp 4.4.9, pyasn1 0.4.5. Python interpreter: 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)] Software documentation and support at http://snmplabs.com/snmpfwd/ Usage: C:\Program Files\Python37\Scripts\snmpfwd-server.py [--help] [--version ] [--debug-snmp=<io|dsp|msgproc|secmod|mibbuild|mibinstrum|acl|proxy|app|all>] [--debug-asn1=<none|encoder|decoder|all>] [--daemonize] [--process-user=] [--process-group=] [--pid-file=] [--logging-method=<syslog|file|stdout|stderr|null[:args>]>] [--log-level=<debug|info|error>] [--config-file=]

C:\tmp> C:\tmp> C:\tmp>snmpfwd-server.py --config-file=server.conf

C:\tmp> C:\tmp>snmpfwd-server.py --config-file=c:\tmp\server.conf

C:\tmp>

Also I have tried to put the parameters logging-method, log-level and debug-snmp but nothing has worked. Maybe it is a problem of windows permissions, but at this moment I have run out of ideas. My operating system is Windows 10 and my user is an administrator of the machine.

I would appreciate any help. Best regards,

Jorge

etingof commented 5 years ago

I personally do not have much experience with Windows logging.

Let's may be start with something simple e.g. --logging-method=file:snmpfwd.log? Though the default is stderr, may be also try --logging-method=stdout? It may also have something to do with user permissions.. Sorry, I do not have anything more specific to offer off the top of my head.

If you could debug that any further to come up with a fix, that would be useful! The code to start with is perhaps here.

JorgeJuanTel commented 5 years ago

Thank very much. I have debugged the code and the problem is in the function PrivilegesOf. The debugger says: AttributeError: module 'snmpfwd.daemon' has no attribute 'PrivilegesOf' I have seen in the daemon.py file that PrivilegesOf is not defined for Windows:

if sys.platform[:3] == 'win': def daemonize(pidfile): raise error.SnmpfwdError('Windows is not inhabited with daemons!') def dropPrivileges(uname, gname): return else:

Is it correct? Maybe I have an old version of daemon.py. I have to tell you that I am a beginner with Python.

In any case, I have defined the class PrivilegesOf inside the 'if sys.platform[:3] == 'win':' and, it works now.

Thank you Best regards,

Jorge

mcarroll1110 commented 4 years ago

I ran into the same issue as Jorge. His solution worked for me. I wish I noticed that it was in the daemon.py script file as I was looking in the wrong place. I am new to Python as well so I'm not sure if I fixed it in the cleanest way.

I am running snmpfwd version 0.4.4 with Python 3.8 on Windows 10 for testing.

For those attempting the same (with a pip installation), the file is located here:

\Lib\site-packages\snmpfwd\daemon.py Original Code Block: ``` if sys.platform[:3] == 'win': def daemonize(pidfile): raise error.SnmpfwdError('Windows is not inhabited with daemons!') def dropPrivileges(uname, gname): return else: import os # original code continues... ``` Work around code changes: ``` if sys.platform[:3] == 'win': def daemonize(pidfile): raise error.SnmpfwdError('Windows is not inhabited with daemons!') def dropPrivileges(uname, gname): return class PrivilegesOf(object): def __init__(self, uname, gname, final=False): return def __enter__(self): return def __exit__(self, *args): return else: import os # original code continues... ``` Hopefully a correction can be added to the source code (by someone more familiar with Python than me).
premananda8 commented 4 years ago

Thank very much. I have debugged the code and the problem is in the function PrivilegesOf. The debugger says: AttributeError: module 'snmpfwd.daemon' has no attribute 'PrivilegesOf' I have seen in the daemon.py file that PrivilegesOf is not defined for Windows:

if sys.platform[:3] == 'win': def daemonize(pidfile): raise error.SnmpfwdError('Windows is not inhabited with daemons!') def dropPrivileges(uname, gname): return else:

Is it correct? Maybe I have an old version of daemon.py. I have to tell you that I am a beginner with Python.

In any case, I have defined the class PrivilegesOf inside the 'if sys.platform[:3] == 'win':' and, it works now.

Thank you Best regards,

Jorge

Helped