Skip to content

Commit

Permalink
Standardize project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
agn-7 committed Aug 25, 2020
1 parent 65a3379 commit fa8805f
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 21 deletions.
45 changes: 41 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,57 @@ docker-compose up --build -d
pip install -r requirements.txt
```

### Run:
### Run by downloading or cloning the repository:

```bash
python __main__.py
```

## Configuration

### Config your desire OID(s) ane metrics:
### Config your desire OID(s) and metrics:

```bash
nano config/cofig.json
```

## Setup through `pip`

```bash
pip install simple-snmp-collector pyserial easydict pysnmp==4.4.9 async-timeout uvloop
```
### Configuration

Create a json config file with the following format:

```
[
{
"isEnable": true,
"name": "snmp-model-1",
"address": "192.168.1.120",
"port": 161,
"timeout": 1,
"retries": 3,
"version": 2,
"sleep_time": 5,
"community": "public",
"metrics": [
{
"isEnable": true,
"tag_name": "a-sample",
"oid": "1.3.6.13.4.1.3.1112"
}
],
"meta_data": [{'key': 'value'}]
}
]
```

### Run

```bash
python -m snmp_collector --config=<path-to-your-config-file.json>
```

---
[**NOTE**]:

Expand Down
88 changes: 88 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@

SNMP collector through an Asyncio event loop
============================================

Setup using docker
------------------

Up and build docker container:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: bash
docker-compose up --build -d
Without docker:
---------------

Install requirements:
^^^^^^^^^^^^^^^^^^^^^

.. code-block:: bash
pip install -r requirements.txt
Run by downloading or cloning the repository:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: bash
python __main__.py
Config your desire OID(s) and metrics:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: bash
nano config/cofig.json
Setup through ``pip``
-------------------------

.. code-block:: bash
pip install simple-snmp-collector pyserial easydict pysnmp==4.4.9 async-timeout uvloop
Configuration
^^^^^^^^^^^^^

Create a json config file with the following format:

.. code-block::
[
{
"isEnable": true,
"name": "snmp-model-1",
"address": "192.168.1.120",
"port": 161,
"timeout": 1,
"retries": 3,
"version": 2,
"sleep_time": 5,
"community": "public",
"metrics": [
{
"isEnable": true,
"tag_name": "a-sample",
"oid": "1.3.6.13.4.1.3.1112"
}
],
"meta_data": [{'key': 'value'}]
}
]
Run
^^^

.. code-block:: bash
python -m snmp_collector --config=<path-to-your-config-file.json>
----

[\ **NOTE**\ ]:


* If you are a Windows user and you don't want to use docker, comment out the ``uvloop`` package form ``requirements.txt``
* The value of ``-8555`` means a problem is occurred during reading data over SNMP or in connection.
10 changes: 2 additions & 8 deletions __main__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
#!/usr/bin/env python

from event_loop.event_loop import EventLoop
from snmp_collector.event_loop import run

__author__ = 'aGn'
__copyright__ = "Copyright 2018, Planet Earth"


if __name__ == "__main__":
print('SNMP Begins')
run()

try:
EventLoop().run_forever()

except KeyboardInterrupt:
import sys
sys.exit(0)
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[metadata]
description-file = README.md
description-file = README.rst
12 changes: 6 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import sys

from setuptools import setup
from event_loop import __version__
from setuptools import setup, find_packages
from snmp_collector import __version__


if sys.version_info[0] < 3:
with open('README.md') as f:
with open('README.rst') as f:
long_description = f.read()
else:
with open('README.md', encoding='utf-8') as f:
with open('README.rst', encoding='utf-8') as f:
long_description = f.read()


Expand All @@ -21,7 +21,7 @@
author='agn-7',
author_email='benyaminjmf@gmail.com',
license='MIT',
packages=['event_loop'],
packages=find_packages(),
keywords=[
'snmp',
'snmp-collector',
Expand All @@ -31,7 +31,7 @@
'docker',
'docker-compose'
],
download_url='https://github.com/agn-7/simple-snmp-collector/archive/1.0.0-rc1.zip',
download_url='https://github.com/agn-7/simple-snmp-collector/archive/1.0.0.zip',
install_requires=[
'pyserial',
'easydict',
Expand Down
2 changes: 1 addition & 1 deletion event_loop/__init__.py → snmp_collector/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .event_loop import *

__version__ = '1.0.0rc3'
__version__ = '1.0.0'
__author__ = 'aGn'
__copyright__ = "Copyright 2018, Planet Earth"
10 changes: 10 additions & 0 deletions snmp_collector/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env python

from .event_loop import run

__author__ = 'aGn'
__copyright__ = "Copyright 2018, Planet Earth"


if __name__ == "__main__":
run()
6 changes: 5 additions & 1 deletion event_loop/event_loop.py → snmp_collector/event_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def run_forever(self):
print("Waiting for SNMP configuration ...")


if __name__ == '__main__':
def run():
print('SNMP Begins')
parser = argparse.ArgumentParser(description='Simple SNMP Collector.')

Expand All @@ -225,3 +225,7 @@ def run_forever(self):

except KeyboardInterrupt:
sys.exit(0)


if __name__ == '__main__':
run()

0 comments on commit fa8805f

Please sign in to comment.