[Python-modules-commits] [bernhard] 01/05: Imported Upstream version 0.2.4
Vincent Bernat
bernat at moszumanska.debian.org
Mon Jun 20 10:21:58 UTC 2016
This is an automated email from the git hooks/post-receive script.
bernat pushed a commit to branch master
in repository bernhard.
commit d207bfd25f47a47285a5fe0ba2dd6b11035fc833
Author: Vincent Bernat <bernat at debian.org>
Date: Mon Jun 20 11:54:29 2016 +0200
Imported Upstream version 0.2.4
---
.gitignore | 4 +
LICENSE | 202 ++++++++++++++++++
MANIFEST.in | 3 +
PKG-INFO | 64 ++++++
README.md | 41 ++++
bernhard.egg-info/PKG-INFO | 64 ++++++
bernhard.egg-info/SOURCES.txt | 13 ++
bernhard.egg-info/dependency_links.txt | 1 +
bernhard.egg-info/not-zip-safe | 1 +
bernhard.egg-info/requires.txt | 1 +
bernhard.egg-info/top_level.txt | 1 +
bernhard/__init__.py | 257 +++++++++++++++++++++++
bernhard/pb.py | 367 +++++++++++++++++++++++++++++++++
setup.cfg | 5 +
setup.py | 42 ++++
15 files changed, 1066 insertions(+)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..6c7aafc
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+*.pyc
+bernhard.egg-info/
+dist/
+build/
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..f6cd2bc
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..9b283fc
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,3 @@
+include .gitignore
+include LICENSE
+include README.md
diff --git a/PKG-INFO b/PKG-INFO
new file mode 100644
index 0000000..0004815
--- /dev/null
+++ b/PKG-INFO
@@ -0,0 +1,64 @@
+Metadata-Version: 1.1
+Name: bernhard
+Version: 0.2.4
+Summary: Python client for Riemann
+Home-page: http://github.com/banjiewen/bernhard.git
+Author: Benjamin Anderspn
+Author-email: b at banjiewen.net
+License: ASF2.0
+Description: # Bernhard
+
+ A simple Python client for [Riemann](http://github.com/aphyr/riemann). Usage:
+
+ ```python
+ import bernhard
+
+ c = bernhard.Client()
+ c.send({'host': 'myhost.foobar.com', 'service': 'myservice', 'metric': 12})
+ q = c.query('true')
+ ```
+
+ Bernhard supports custom attributes with the syntax:
+ ```python
+ import bernhard
+
+ c = bernhard.Client()
+
+ c.send({'host': 'awesome.host.com', 'attributes': {'sky': 'sunny', 'sea': 'agitated'}})
+ ```
+
+ Querying the index is as easy as:
+ ```python
+ import bernhard
+
+ c = bernhard.Client()
+ q = c.query('true')
+ for e in q:
+ print "Host:", e.host, "State:", e.state
+ ```
+
+
+ ## Installing
+
+ ```bash
+ pip install bernhard
+ ```
+
+ You may encounter issues with the `protobuf` dependency; if so, just run `pip
+ install protobuf` manually, then `pip install bernhard`.
+
+
+Platform: UNKNOWN
+Classifier: Development Status :: 4 - Beta
+Classifier: Environment :: Other Environment
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: Apache Software License
+Classifier: Operating System :: MacOS :: MacOS X
+Classifier: Operating System :: POSIX
+Classifier: Operating System :: Unix
+Classifier: Programming Language :: Python
+Classifier: Programming Language :: Python :: 2
+Classifier: Programming Language :: Python :: 3
+Classifier: Topic :: Internet :: Log Analysis
+Classifier: Topic :: Utilities
+Classifier: Topic :: System :: Networking :: Monitoring
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..094c83e
--- /dev/null
+++ b/README.md
@@ -0,0 +1,41 @@
+# Bernhard
+
+A simple Python client for [Riemann](http://github.com/aphyr/riemann). Usage:
+
+```python
+import bernhard
+
+c = bernhard.Client()
+c.send({'host': 'myhost.foobar.com', 'service': 'myservice', 'metric': 12})
+q = c.query('true')
+```
+
+Bernhard supports custom attributes with the syntax:
+```python
+import bernhard
+
+c = bernhard.Client()
+
+c.send({'host': 'awesome.host.com', 'attributes': {'sky': 'sunny', 'sea': 'agitated'}})
+```
+
+Querying the index is as easy as:
+```python
+import bernhard
+
+c = bernhard.Client()
+q = c.query('true')
+for e in q:
+ print "Host:", e.host, "State:", e.state
+```
+
+
+## Installing
+
+```bash
+pip install bernhard
+```
+
+You may encounter issues with the `protobuf` dependency; if so, just run `pip
+install protobuf` manually, then `pip install bernhard`.
+
diff --git a/bernhard.egg-info/PKG-INFO b/bernhard.egg-info/PKG-INFO
new file mode 100644
index 0000000..0004815
--- /dev/null
+++ b/bernhard.egg-info/PKG-INFO
@@ -0,0 +1,64 @@
+Metadata-Version: 1.1
+Name: bernhard
+Version: 0.2.4
+Summary: Python client for Riemann
+Home-page: http://github.com/banjiewen/bernhard.git
+Author: Benjamin Anderspn
+Author-email: b at banjiewen.net
+License: ASF2.0
+Description: # Bernhard
+
+ A simple Python client for [Riemann](http://github.com/aphyr/riemann). Usage:
+
+ ```python
+ import bernhard
+
+ c = bernhard.Client()
+ c.send({'host': 'myhost.foobar.com', 'service': 'myservice', 'metric': 12})
+ q = c.query('true')
+ ```
+
+ Bernhard supports custom attributes with the syntax:
+ ```python
+ import bernhard
+
+ c = bernhard.Client()
+
+ c.send({'host': 'awesome.host.com', 'attributes': {'sky': 'sunny', 'sea': 'agitated'}})
+ ```
+
+ Querying the index is as easy as:
+ ```python
+ import bernhard
+
+ c = bernhard.Client()
+ q = c.query('true')
+ for e in q:
+ print "Host:", e.host, "State:", e.state
+ ```
+
+
+ ## Installing
+
+ ```bash
+ pip install bernhard
+ ```
+
+ You may encounter issues with the `protobuf` dependency; if so, just run `pip
+ install protobuf` manually, then `pip install bernhard`.
+
+
+Platform: UNKNOWN
+Classifier: Development Status :: 4 - Beta
+Classifier: Environment :: Other Environment
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: Apache Software License
+Classifier: Operating System :: MacOS :: MacOS X
+Classifier: Operating System :: POSIX
+Classifier: Operating System :: Unix
+Classifier: Programming Language :: Python
+Classifier: Programming Language :: Python :: 2
+Classifier: Programming Language :: Python :: 3
+Classifier: Topic :: Internet :: Log Analysis
+Classifier: Topic :: Utilities
+Classifier: Topic :: System :: Networking :: Monitoring
diff --git a/bernhard.egg-info/SOURCES.txt b/bernhard.egg-info/SOURCES.txt
new file mode 100644
index 0000000..97c2201
--- /dev/null
+++ b/bernhard.egg-info/SOURCES.txt
@@ -0,0 +1,13 @@
+.gitignore
+LICENSE
+MANIFEST.in
+README.md
+setup.py
+bernhard/__init__.py
+bernhard/pb.py
+bernhard.egg-info/PKG-INFO
+bernhard.egg-info/SOURCES.txt
+bernhard.egg-info/dependency_links.txt
+bernhard.egg-info/not-zip-safe
+bernhard.egg-info/requires.txt
+bernhard.egg-info/top_level.txt
\ No newline at end of file
diff --git a/bernhard.egg-info/dependency_links.txt b/bernhard.egg-info/dependency_links.txt
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/bernhard.egg-info/dependency_links.txt
@@ -0,0 +1 @@
+
diff --git a/bernhard.egg-info/not-zip-safe b/bernhard.egg-info/not-zip-safe
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/bernhard.egg-info/not-zip-safe
@@ -0,0 +1 @@
+
diff --git a/bernhard.egg-info/requires.txt b/bernhard.egg-info/requires.txt
new file mode 100644
index 0000000..d8c5564
--- /dev/null
+++ b/bernhard.egg-info/requires.txt
@@ -0,0 +1 @@
+protobuf >= 2.4
\ No newline at end of file
diff --git a/bernhard.egg-info/top_level.txt b/bernhard.egg-info/top_level.txt
new file mode 100644
index 0000000..50f5423
--- /dev/null
+++ b/bernhard.egg-info/top_level.txt
@@ -0,0 +1 @@
+bernhard
diff --git a/bernhard/__init__.py b/bernhard/__init__.py
new file mode 100644
index 0000000..f3d238b
--- /dev/null
+++ b/bernhard/__init__.py
@@ -0,0 +1,257 @@
+# -*- coding: utf-8 -
+
+import logging
+log = logging.getLogger(__name__)
+
+import socket
+import ssl
+import struct
+import sys
+
+from . import pb
+
+string_type = str
+if sys.version_info[1] < 3:
+ string_type = basestring
+
+class TransportError(Exception):
+ def __init__(self, msg):
+ self.msg = msg
+
+ def __str__(self):
+ return self.msg
+
+
+class TCPTransport(object):
+ def __init__(self, host, port):
+ for res in socket.getaddrinfo(host, port, socket.AF_UNSPEC, socket.SOCK_STREAM):
+ af, socktype, proto, canonname, sa = res
+ try:
+ log.debug("Creating socket with %s %s %s", af, socktype, proto)
+ self.sock = socket.socket(af, socktype, proto)
+ self.sock.settimeout(15.0)
+ except socket.error as e:
+ log.exception("Exception creating TCP socket: %s", e)
+ self.sock = None
+ continue
+ try:
+ self.sock.connect(sa)
+ except socket.error as e:
+ log.exception("Exception connecting to TCP socket: %s", e)
+ self.sock.close()
+ self.sock = None
+ continue
+ break
+ if self.sock is None:
+ raise TransportError("Could not open TCP socket.")
+
+ def close(self):
+ self.sock.close()
+
+ def read_exactly(self, sock, size):
+ buffer = ''
+ while len(buffer) < size:
+ data = sock.recv(size - len(buffer))
+ if not data:
+ log.debug("Expected to read %s bytes, but read %s bytes", size, len(buffer))
+ break
+ buffer += data
+ return buffer
+
+ def write(self, message):
+ try:
+ # Tx length header and message
+ log.debug("Sending event to Riemann")
+ self.sock.sendall(struct.pack('!I', len(message)) + message)
+
+ # Rx length header
+ log.debug("Reading Riemann Response Length Header")
+ response = self.read_exactly(self.sock, 4)
+ rxlen = struct.unpack('!I', response)[0]
+ log.debug("Header Length Is: %d", rxlen)
+
+ # Rx entire response
+ log.debug("Reading Riemann Response")
+ response = self.read_exactly(self.sock, rxlen)
+
+ return response
+ except (socket.error, struct.error) as e:
+ log.exception("Exception sending event to Riemann over TCP socket: %s", e)
+ raise TransportError(str(e))
+
+
+class SSLTransport(TCPTransport):
+ def __init__(self, host, port, keyfile=None, certfile=None, ca_certs=None):
+ log.debug("Using SSL Transport")
+
+ TCPTransport.__init__(self, host, port)
+
+ self.sock = ssl.wrap_socket(self.sock,
+ keyfile=keyfile,
+ certfile=certfile,
+ cert_reqs=ssl.CERT_REQUIRED,
+ ssl_version=ssl.PROTOCOL_TLSv1,
+ ca_certs=ca_certs)
+
+
+class UDPTransport(object):
+ def __init__(self, host, port):
+ log.debug("Using UDP Transport")
+
+ self.host = None
+ self.port = None
+ for res in socket.getaddrinfo(host, port, socket.AF_UNSPEC, socket.SOCK_DGRAM):
+ af, socktype, proto, canonname, sa = res
+ try:
+ self.sock = socket.socket(af, socktype, proto)
+ self.host = sa[0]
+ self.port = sa[1]
+ except socket.error as e:
+ log.exception("Exception opening socket: %s", e)
+ self.sock = None
+ continue
+ break
+ if self.sock is None:
+ raise TransportError("Could not open socket.")
+
+ def close(self):
+ self.sock.close()
+
+ def write(self, message):
+ try:
+ self.sock.sendto(message, (self.host, self.port))
+ except socket.error as e:
+ log.exception("Exception writing to socket: %s", e)
+ raise TransportError(str(e))
+
+
+class Event(object):
+ def __init__(self, event=None, params=None):
+ if event:
+ self.event = event
+ elif params:
+ self.event = pb.Event()
+ for key, value in params.items():
+ setattr(self, key, value)
+ else:
+ self.event = pb.Event()
+
+ def __getattr__(self, name):
+ if name == 'metric':
+ name = 'metric_f'
+ if name in set(f.name for f in pb.Event.DESCRIPTOR.fields):
+ return getattr(self.event, name)
+
+ def __setattr__(self, name, value):
+ if name == 'metric':
+ name = 'metric_f'
+ if name == 'tags':
+ self.event.tags.extend(value)
+ elif name == 'attributes':
+ if type(value) == dict:
+ for key, val in value.items():
+ a = self.event.attributes.add()
+ a.key = key
+ if isinstance(val, bytes):
+ val = val.decode('utf-8')
+ elif not isinstance(val, string_type):
+ val = string_type(val)
+ a.value = string_type(val)
+ else:
+ raise TypeError("'attributes' parameter must be type 'dict'")
+ elif name in set(f.name for f in pb.Event.DESCRIPTOR.fields):
+ object.__setattr__(self.event, name, value)
+ else:
+ object.__setattr__(self, name, value)
+
+ def __str__(self):
+ return str(self.event)
+
+
+class Message(object):
+ def __init__(self, message=None, events=None, raw=None, query=None):
+ if raw:
+ self.message = pb.Msg().FromString(raw)
+ elif message:
+ self.message = message
+ elif events:
+ self.message = pb.Msg()
+ self.message.events.extend([e.event for e in events])
+ elif query:
+ self.message = pb.Msg()
+ self.message.query.string = str(query)
+ else:
+ self.message = pb.Msg()
+
+ def __getattr__(self, name):
+ if name in set(f.name for f in pb.Msg.DESCRIPTOR.fields):
+ return getattr(self.message, name)
+
+ def __setattr__(self, name, value):
+ if name in set(f.name for f in pb.Msg.DESCRIPTOR.fields):
+ object.__setattr__(self.message, name, value)
+ else:
+ object.__setattr__(self, name, value)
+
+ # Special-case the `events` field so we get boxed objects
+ @property
+ def events(self):
+ return [Event(event=e) for e in self.message.events]
+
+ @property
+ def raw(self):
+ return self.message.SerializeToString()
+
+
+class Client(object):
+ def __init__(self, host='127.0.0.1', port=5555, transport=TCPTransport):
+ self.host = host
+ self.port = port
+ self.transport = transport
+ self.connection = None
+
+ def connect(self):
+ self.connection = self.transport(self.host, self.port)
+
+ def disconnect(self):
+ try:
+ self.connection.close()
+ except Exception as e:
+ log.exception("Exception disconnecting client: %s", e)
+ pass
+ self.connection = None
+
+ def transmit(self, message):
+ for i in range(2):
+ if not self.connection:
+ self.connect()
+ try:
+ raw = self.connection.write(message.raw)
+ return Message(raw=raw)
+ except TransportError:
+ self.disconnect()
+ return Message()
+
+ def send(self, *events):
+ message = Message(events=[Event(params=event) for event in events])
+ response = self.transmit(message)
+ return response.ok
+
+ def query(self, q):
+ message = Message(query=q)
+ response = self.transmit(message)
+ return response.events
+
+
+class SSLClient(Client):
+ def __init__(self, host='127.0.0.1', port=5554,
+ keyfile=None, certfile=None, ca_certs=None):
+ Client.__init__(self, host=host, port=port, transport=SSLTransport)
+
+ self.keyfile = keyfile
+ self.certfile = certfile
+ self.ca_certs = ca_certs
+
+ def connect(self):
+ self.connection = self.transport(self.host, self.port, self.keyfile,
+ self.certfile, self.ca_certs)
diff --git a/bernhard/pb.py b/bernhard/pb.py
new file mode 100644
index 0000000..ef78fd2
--- /dev/null
+++ b/bernhard/pb.py
@@ -0,0 +1,367 @@
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: proto.proto
+
+from google.protobuf import descriptor as _descriptor
+from google.protobuf import message as _message
+from google.protobuf import reflection as _reflection
+from google.protobuf import descriptor_pb2
+# @@protoc_insertion_point(imports)
+
+
+
+
+DESCRIPTOR = _descriptor.FileDescriptor(
+ name='proto.proto',
+ package='',
+ serialized_pb='\n\x0bproto.proto\"\x81\x01\n\x05State\x12\x0c\n\x04time\x18\x01 \x01(\x03\x12\r\n\x05state\x18\x02 \x01(\t\x12\x0f\n\x07service\x18\x03 \x01(\t\x12\x0c\n\x04host\x18\x04 \x01(\t\x12\x13\n\x0b\x64\x65scription\x18\x05 \x01(\t\x12\x0c\n\x04once\x18\x06 \x01(\x08\x12\x0c\n\x04tags\x18\x07 \x03(\t\x12\x0b\n\x03ttl\x18\x08 \x01(\x02\"\xce\x01\n\x05\x45vent\x12\x0c\n\x04time\x18\x01 \x01(\x03\x12\r\n\x05state\x18\x02 \x01(\t\x12\x0f\n\x07service\x18\x03 \x01(\t\x12\x0c\n\x04h [...]
+
+
+
+
+_STATE = _descriptor.Descriptor(
+ name='State',
+ full_name='State',
+ filename=None,
+ file=DESCRIPTOR,
+ containing_type=None,
+ fields=[
+ _descriptor.FieldDescriptor(
+ name='time', full_name='State.time', index=0,
+ number=1, type=3, cpp_type=2, label=1,
+ has_default_value=False, default_value=0,
+ message_type=None, enum_type=None, containing_type=None,
+ is_extension=False, extension_scope=None,
+ options=None),
+ _descriptor.FieldDescriptor(
+ name='state', full_name='State.state', index=1,
+ number=2, type=9, cpp_type=9, label=1,
+ has_default_value=False, default_value=u"",
+ message_type=None, enum_type=None, containing_type=None,
+ is_extension=False, extension_scope=None,
+ options=None),
+ _descriptor.FieldDescriptor(
+ name='service', full_name='State.service', index=2,
+ number=3, type=9, cpp_type=9, label=1,
+ has_default_value=False, default_value=u"",
+ message_type=None, enum_type=None, containing_type=None,
+ is_extension=False, extension_scope=None,
+ options=None),
+ _descriptor.FieldDescriptor(
+ name='host', full_name='State.host', index=3,
+ number=4, type=9, cpp_type=9, label=1,
+ has_default_value=False, default_value=u"",
+ message_type=None, enum_type=None, containing_type=None,
+ is_extension=False, extension_scope=None,
+ options=None),
+ _descriptor.FieldDescriptor(
+ name='description', full_name='State.description', index=4,
+ number=5, type=9, cpp_type=9, label=1,
+ has_default_value=False, default_value=u"",
+ message_type=None, enum_type=None, containing_type=None,
+ is_extension=False, extension_scope=None,
+ options=None),
+ _descriptor.FieldDescriptor(
+ name='once', full_name='State.once', index=5,
+ number=6, type=8, cpp_type=7, label=1,
+ has_default_value=False, default_value=False,
+ message_type=None, enum_type=None, containing_type=None,
+ is_extension=False, extension_scope=None,
+ options=None),
+ _descriptor.FieldDescriptor(
+ name='tags', full_name='State.tags', index=6,
+ number=7, type=9, cpp_type=9, label=3,
+ has_default_value=False, default_value=[],
+ message_type=None, enum_type=None, containing_type=None,
+ is_extension=False, extension_scope=None,
+ options=None),
+ _descriptor.FieldDescriptor(
+ name='ttl', full_name='State.ttl', index=7,
+ number=8, type=2, cpp_type=6, label=1,
+ has_default_value=False, default_value=0,
+ message_type=None, enum_type=None, containing_type=None,
+ is_extension=False, extension_scope=None,
+ options=None),
+ ],
+ extensions=[
+ ],
+ nested_types=[],
+ enum_types=[
+ ],
+ options=None,
+ is_extendable=False,
+ extension_ranges=[],
+ serialized_start=16,
+ serialized_end=145,
+)
+
+
+_EVENT = _descriptor.Descriptor(
+ name='Event',
+ full_name='Event',
+ filename=None,
+ file=DESCRIPTOR,
+ containing_type=None,
+ fields=[
+ _descriptor.FieldDescriptor(
+ name='time', full_name='Event.time', index=0,
+ number=1, type=3, cpp_type=2, label=1,
+ has_default_value=False, default_value=0,
+ message_type=None, enum_type=None, containing_type=None,
+ is_extension=False, extension_scope=None,
+ options=None),
+ _descriptor.FieldDescriptor(
+ name='state', full_name='Event.state', index=1,
+ number=2, type=9, cpp_type=9, label=1,
+ has_default_value=False, default_value=u"",
+ message_type=None, enum_type=None, containing_type=None,
+ is_extension=False, extension_scope=None,
+ options=None),
+ _descriptor.FieldDescriptor(
+ name='service', full_name='Event.service', index=2,
+ number=3, type=9, cpp_type=9, label=1,
+ has_default_value=False, default_value=u"",
+ message_type=None, enum_type=None, containing_type=None,
+ is_extension=False, extension_scope=None,
+ options=None),
+ _descriptor.FieldDescriptor(
+ name='host', full_name='Event.host', index=3,
+ number=4, type=9, cpp_type=9, label=1,
+ has_default_value=False, default_value=u"",
+ message_type=None, enum_type=None, containing_type=None,
+ is_extension=False, extension_scope=None,
+ options=None),
+ _descriptor.FieldDescriptor(
+ name='description', full_name='Event.description', index=4,
+ number=5, type=9, cpp_type=9, label=1,
+ has_default_value=False, default_value=u"",
+ message_type=None, enum_type=None, containing_type=None,
+ is_extension=False, extension_scope=None,
+ options=None),
+ _descriptor.FieldDescriptor(
+ name='tags', full_name='Event.tags', index=5,
+ number=7, type=9, cpp_type=9, label=3,
+ has_default_value=False, default_value=[],
+ message_type=None, enum_type=None, containing_type=None,
+ is_extension=False, extension_scope=None,
+ options=None),
+ _descriptor.FieldDescriptor(
+ name='ttl', full_name='Event.ttl', index=6,
+ number=8, type=2, cpp_type=6, label=1,
+ has_default_value=False, default_value=0,
+ message_type=None, enum_type=None, containing_type=None,
+ is_extension=False, extension_scope=None,
+ options=None),
+ _descriptor.FieldDescriptor(
+ name='attributes', full_name='Event.attributes', index=7,
+ number=9, type=11, cpp_type=10, label=3,
+ has_default_value=False, default_value=[],
+ message_type=None, enum_type=None, containing_type=None,
+ is_extension=False, extension_scope=None,
+ options=None),
+ _descriptor.FieldDescriptor(
+ name='metric_sint64', full_name='Event.metric_sint64', index=8,
+ number=13, type=18, cpp_type=2, label=1,
+ has_default_value=False, default_value=0,
+ message_type=None, enum_type=None, containing_type=None,
+ is_extension=False, extension_scope=None,
+ options=None),
+ _descriptor.FieldDescriptor(
+ name='metric_d', full_name='Event.metric_d', index=9,
+ number=14, type=1, cpp_type=5, label=1,
+ has_default_value=False, default_value=0,
+ message_type=None, enum_type=None, containing_type=None,
+ is_extension=False, extension_scope=None,
+ options=None),
+ _descriptor.FieldDescriptor(
+ name='metric_f', full_name='Event.metric_f', index=10,
+ number=15, type=2, cpp_type=6, label=1,
+ has_default_value=False, default_value=0,
+ message_type=None, enum_type=None, containing_type=None,
+ is_extension=False, extension_scope=None,
+ options=None),
+ ],
+ extensions=[
+ ],
+ nested_types=[],
+ enum_types=[
+ ],
+ options=None,
+ is_extendable=False,
+ extension_ranges=[],
+ serialized_start=148,
+ serialized_end=354,
+)
+
+
+_QUERY = _descriptor.Descriptor(
+ name='Query',
+ full_name='Query',
+ filename=None,
+ file=DESCRIPTOR,
+ containing_type=None,
+ fields=[
+ _descriptor.FieldDescriptor(
+ name='string', full_name='Query.string', index=0,
+ number=1, type=9, cpp_type=9, label=1,
+ has_default_value=False, default_value=u"",
+ message_type=None, enum_type=None, containing_type=None,
+ is_extension=False, extension_scope=None,
+ options=None),
+ ],
+ extensions=[
+ ],
+ nested_types=[],
+ enum_types=[
+ ],
+ options=None,
+ is_extendable=False,
+ extension_ranges=[],
+ serialized_start=356,
+ serialized_end=379,
+)
+
+
+_MSG = _descriptor.Descriptor(
+ name='Msg',
+ full_name='Msg',
+ filename=None,
+ file=DESCRIPTOR,
+ containing_type=None,
+ fields=[
+ _descriptor.FieldDescriptor(
+ name='ok', full_name='Msg.ok', index=0,
+ number=2, type=8, cpp_type=7, label=1,
+ has_default_value=False, default_value=False,
+ message_type=None, enum_type=None, containing_type=None,
+ is_extension=False, extension_scope=None,
+ options=None),
+ _descriptor.FieldDescriptor(
+ name='error', full_name='Msg.error', index=1,
+ number=3, type=9, cpp_type=9, label=1,
+ has_default_value=False, default_value=u"",
+ message_type=None, enum_type=None, containing_type=None,
+ is_extension=False, extension_scope=None,
+ options=None),
+ _descriptor.FieldDescriptor(
... 181 lines suppressed ...
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/bernhard.git
More information about the Python-modules-commits
mailing list