Example #1
0
    def __init__(self, hub, cert_conf=None, secure=True, app_name=None,
                 app_id=None):
        """
        Initialize a ``NotificationServer`` object.

        :param hub: The address of the hub, as a tuple of hostname and
                    port.
        :param cert_conf: The path to the certificate configuration
                          file.  Optional.
        :param secure: If ``False``, SSL will not be used.  Defaults
                       to ``True``.
        :param app_name: The name of the application.  If not
                         specified, the name is derived from
                         ``sys.argv[0]``.
        :param app_id: A UUID for notifications generated internal to
                       the notifier.  If not specified, a random UUID
                       will be generated.
        """

        # Handle the arguments
        self._hub = hub
        self._manager = tendril.get_manager('tcp', util.outgoing_endpoint(hub))
        self._wrapper = util.cert_wrapper(cert_conf, 'notifier', secure=secure)

        # Save the app name and ID
        self._app_name = app_name or os.path.basename(sys.argv[0])
        self._app_id = app_id or str(uuid.uuid4())

        # Track running status and the queue of notifications
        self._hub_app = None
        self._notifications = []
        self._notify_event = gevent.event.Event()

        # Set up behavior on signals
        gevent.signal(signal.SIGINT, self.stop)
        gevent.signal(signal.SIGTERM, self.stop)
        try:  # pragma: no cover
            # Force an immediate shutdown
            gevent.signal(signal.SIGUSR1, self.shutdown)
        except Exception:  # pragma: no cover
            # Ignore errors; SIGUSR1 isn't everywhere
            pass
Example #2
0
def send_notification(hub, app_name, summary, body,
                      urgency=None, category=None, id=None,
                      cert_conf=None, secure=True):
    """
    Sends a notification via the configured HeyU hub.  The hub address
    is read from the "~/.heyu.hub" file, which should contain either
    "hostname" or "hostname:port".  If the file doesn't exist, and
    "--host" is not given, "localhost" will be tried.  Prints out the
    notification ID if the notification is accepted.  Note that
    certificate configuration is specified in "~/.heyu.cert" by
    default.

    :param hub: The address of the hub, as a tuple of hostname and
                port.
    :param app_name: The name of the application the notification is
                     for.
    :param summary: A summary of the notification.
    :param body: The body of the notification.
    :param urgency: The urgency level for the notification.  Optional.
    :param category: A category for the notification.  Optional.
    :param id: The ID of a notification to replace.  Optional.
    :param cert_conf: The path to the certificate configuration file.
                      Optional.
    :param secure: If ``False``, SSL will not be used.  Defaults to
                   ``True``.
    """

    # Look up the manager
    manager = tendril.get_manager('tcp', util.outgoing_endpoint(hub))
    manager.start()

    # Connect to the hub
    app = tendril.TendrilPartial(SubmitterApplication,
                                 app_name, summary, body,
                                 urgency, category, id)
    wrapper = util.cert_wrapper(cert_conf, 'submitter', secure=secure)
    manager.connect(hub, app, wrapper)

    # Wait for the submitter to exit
    gevent.wait()
Example #3
0
    def test_ipv6(self, mock_addr_info):
        result = util.outgoing_endpoint('target')

        self.assertEqual(('::', 0), result)
        mock_addr_info.assert_called_once_with('target')