侦听TCP端口上JSON事件的CANopsis连接器
tcp2canopsis的Python项目详细描述
此包提供一个连接器,用于侦听TCP端口上的事件。
用法
在指定的端口(8000在本例中)上运行脚本,并使用url AMQP服务器的:
$ tcp2canopsis -p 8000 -a "amqp://guest:guest@localhost:5672/" -t token
然后使用telnet发布事件:
$ telnet localhost 8000 Trying ::1... Connected to localhost. Escape character is '^]'. token {"connector": "test", "connector_name": "testname", "event_type": "check", "source_type": "resource", "component": "testcmp", "resource": "testrsrc", "state": 0, "output": "test output"} {"connector": "test", "connector_name": "testname", "event_type": "check", "source_type": "resource", "component": "testcmp", "resource": "testrsrc", "state": 1, "output": "test output 2"} {"connector": "test", "connector_name": "testname", "event_type": "check", "source_type": "resource", "component": "testcmp", "resource": "testrsrc", "state": 0, "output": "test output 3"} Connection closed by foreign host.
或者在json文件中:
{"tcp2canopsis":{"port":8000,"amqp":"amqp://guest:guest@localhost:5672/","token":"token"}}
并使用以下命令加载文件:
$ tcp2canopsis -c path/to/config.json
安装
只需键入:
$ pip install tcp2canopsis
或者,在本地安装:
$ ./makefile
这将在当前文件夹中创建一个虚拟python环境,并安装由requirements.txt列出的依赖项。 最后,它将执行python setup.py install。
执行此脚本后,连接器将在当前文件夹(现在是虚拟python环境)中可用。