Пример #1
0
    def __init__(self, name, control_name=None, svc_args=[]):
        """
        Initialize a service controlled by Monit.

        ``name``
          Human-friendly name for the service.
        ``control_name``
          Name that the underlying service control system uses to
          identify the service.
        ``svc_args``
          Command-line arguments specific to this service, in the
          format expected by argparse_. Monit services require that
          ``svc_args`` contains a list of hosts on which you wish to
          control services. Monit services also use the following
          options, if provided:

          ``--username``
            Username to use when authenticating to the Monit HTTP API.
          ``--password``
            Password to use when authenticating to the Monit HTTP API.
          ``--port``
            Port on which to connect to the Monit HTTP API.
          ``--realm``
            Authentication realm to use when authenticating to the Monit
            HTTP API.

        .. _argparse: http://docs.python.org/library/argparse.html
        """
        Service.__init__(self, name, control_name=control_name)
        self.auth = url.HTTPBasicAuthHandler()
        self.opener = None
        self.uri = {}
        parser = self._init_parser()
        args = parser.parse_known_args(svc_args)[0]
        for host in args.hosts:
            self.uri[host] = 'http://%s:%s' % (host, args.port)
            # Configure HTTP Basic Authentication for the Monit web API.
            self.auth.add_password(realm=args.realm,
                                   uri=self.uri[host],
                                   user=args.username,
                                   passwd=args.password)
        self.opener = url.build_opener(self.auth)
        url.install_opener(self.opener)
Пример #2
0
 def _init_parser(cls):
     parser = Service._init_parser()
     parser.add_argument('hosts', nargs='+',
                         help='Hosts on which you wish to control the '
                         'monit service.')
     parser.add_argument('-u', '--username', default='',
                         help='Username to use when authenticating to the '
                         'underlying service control mechanism.')
     parser.add_argument('--password', default='',
                         help='Password to use when authenticating to the '
                         'underlying service control mechanism.')
     parser.add_argument('--port', type=int, default=2812,
                         help='Port where the Monit API is listening on '
                         'the given hosts')
     parser.add_argument('--realm', default='monit',
                         help='Authentication realm to use when '
                         'authenticating to the Monit API.')
     return parser
Пример #3
0
 def _init_parser(cls):
     parser = Service._init_parser()
     parser.add_argument("hosts", nargs="+", help="Hosts on which you wish to control the " "monit service.")
     parser.add_argument(
         "-u",
         "--username",
         default="",
         help="Username to use when authenticating to the " "underlying service control mechanism.",
     )
     parser.add_argument(
         "--password",
         default="",
         help="Password to use when authenticating to the " "underlying service control mechanism.",
     )
     parser.add_argument(
         "--port", type=int, default=2812, help="Port where the Monit API is listening on " "the given hosts"
     )
     parser.add_argument(
         "--realm", default="monit", help="Authentication realm to use when " "authenticating to the Monit API."
     )
     return parser