Beispiel #1
0
class SatelliteLink(Item):
    """SatelliteLink is a common Class for link to satellite for
    Arbiter with Conf Dispatcher.

    """
    # id = 0 each Class will have it's own id

    properties = Item.properties.copy()
    properties.update({
        'address':         StringProp(default='localhost', fill_brok=['full_status']),
        'timeout':         IntegerProp(default=3, fill_brok=['full_status']),
        'data_timeout':    IntegerProp(default=120, fill_brok=['full_status']),
        'check_interval':  IntegerProp(default=60, fill_brok=['full_status']),
        'max_check_attempts': IntegerProp(default=3, fill_brok=['full_status']),
        'spare':              BoolProp(default=False, fill_brok=['full_status']),
        'manage_sub_realms':  BoolProp(default=True, fill_brok=['full_status']),
        'manage_arbiters':    BoolProp(default=False, fill_brok=['full_status'], to_send=True),
        'modules':            ListProp(default=[''], to_send=True, split_on_coma=True),
        'polling_interval':   IntegerProp(default=1, fill_brok=['full_status'], to_send=True),
        'use_timezone':       StringProp(default='NOTSET', to_send=True),
        'realm':              StringProp(default='', fill_brok=['full_status'],
                                         brok_transformation=get_obj_name_two_args_and_void),
        'satellitemap':       DictProp(default={}, elts_prop=AddrProp, to_send=True, override=True),
        'use_ssl':             BoolProp(default=False, fill_brok=['full_status']),
        'hard_ssl_name_check': BoolProp(default=True, fill_brok=['full_status']),
        'passive':             BoolProp(default=False, fill_brok=['full_status'], to_send=True),
    })

    running_properties = Item.running_properties.copy()
    running_properties.update({
        'con':                  StringProp(default=None),
        'alive':                BoolProp(default=True, fill_brok=['full_status']),
        'broks':                StringProp(default=[]),

        # the number of failed attempt
        'attempt':              StringProp(default=0, fill_brok=['full_status']),

        # can be network ask or not (dead or check in timeout or error)
        'reachable':            BoolProp(default=False, fill_brok=['full_status']),
        'last_check':           IntegerProp(default=0, fill_brok=['full_status']),
        'managed_confs':        StringProp(default={}),
    })

    def __init__(self, *args, **kwargs):
        super(SatelliteLink, self).__init__(*args, **kwargs)

        self.arb_satmap = {'address': '0.0.0.0', 'port': 0}
        if hasattr(self, 'address'):
            self.arb_satmap['address'] = self.address
        if hasattr(self, 'port'):
            try:
                self.arb_satmap['port'] = int(self.port)
            except Exception:
                pass


    def set_arbiter_satellitemap(self, satellitemap):
        """
            arb_satmap is the satellitemap in current context:
                - A SatelliteLink is owned by an Arbiter
                - satellitemap attribute of SatelliteLink is the map
                  defined IN THE satellite configuration
                  but for creating connections, we need the have the satellitemap of the Arbiter
        """
        self.arb_satmap = {'address': self.address, 'port': self.port, 'use_ssl': self.use_ssl,
                           'hard_ssl_name_check': self.hard_ssl_name_check}
        self.arb_satmap.update(satellitemap)


    def create_connection(self):
        self.con = HTTPClient(address=self.arb_satmap['address'], port=self.arb_satmap['port'],
                              timeout=self.timeout, data_timeout=self.data_timeout,
                              use_ssl=self.use_ssl,
                              strong_ssl=self.hard_ssl_name_check
                              )
        self.uri = self.con.uri


    def put_conf(self, conf):
        if self.con is None:
            self.create_connection()

        # Maybe the connection was not ok, bail out
        if not self.con:
            return False

        try:
            self.con.get('ping')
            self.con.post('put_conf', {'conf': conf}, wait='long')
            print "PUT CONF SUCESS", self.get_name()
            return True
        except HTTPExceptions, exp:
            self.con = None
            logger.error("Failed sending configuration for %s: %s", self.get_name(), str(exp))
            return False
Beispiel #2
0
class SatelliteLink(Item):
    """SatelliteLink is a common Class for link to satellite for
    Arbiter with Conf Dispatcher.

    """

    # id = 0 each Class will have it's own id

    properties = Item.properties.copy()
    properties.update(
        {
            "address": StringProp(fill_brok=["full_status"]),
            "timeout": IntegerProp(default="3", fill_brok=["full_status"]),
            "data_timeout": IntegerProp(default="120", fill_brok=["full_status"]),
            "check_interval": IntegerProp(default="60", fill_brok=["full_status"]),
            "max_check_attempts": IntegerProp(default="3", fill_brok=["full_status"]),
            "spare": BoolProp(default="0", fill_brok=["full_status"]),
            "manage_sub_realms": BoolProp(default="1", fill_brok=["full_status"]),
            "manage_arbiters": BoolProp(default="0", fill_brok=["full_status"], to_send=True),
            "modules": ListProp(default="", to_send=True),
            "polling_interval": IntegerProp(default="1", fill_brok=["full_status"], to_send=True),
            "use_timezone": StringProp(default="NOTSET", to_send=True),
            "realm": StringProp(
                default="", fill_brok=["full_status"], brok_transformation=get_obj_name_two_args_and_void
            ),
            "satellitemap": DictProp(default=None, elts_prop=AddrProp, to_send=True, override=True),
            "use_ssl": BoolProp(default="0", fill_brok=["full_status"]),
            "hard_ssl_name_check": BoolProp(default="0", fill_brok=["full_status"]),
            "passive": BoolProp(default="0", fill_brok=["full_status"], to_send=True),
        }
    )

    running_properties = Item.running_properties.copy()
    running_properties.update(
        {
            "con": StringProp(default=None),
            "alive": StringProp(default=True, fill_brok=["full_status"]),
            "broks": StringProp(default=[]),
            "attempt": StringProp(default=0, fill_brok=["full_status"]),  # the number of failed attempt
            "reachable": StringProp(
                default=False, fill_brok=["full_status"]
            ),  # can be network ask or not (dead or check in timeout or error)
            "last_check": IntegerProp(default=0, fill_brok=["full_status"]),
            "managed_confs": StringProp(default={}),
        }
    )

    def __init__(self, *args, **kwargs):
        super(SatelliteLink, self).__init__(*args, **kwargs)

        self.arb_satmap = {"address": "0.0.0.0", "port": 0}
        if hasattr(self, "address"):
            self.arb_satmap["address"] = self.address
        if hasattr(self, "port"):
            try:
                self.arb_satmap["port"] = int(self.port)
            except:
                pass

    def set_arbiter_satellitemap(self, satellitemap):
        """
            arb_satmap is the satellitemap in current context:
                - A SatelliteLink is owned by an Arbiter
                - satellitemap attribute of SatelliteLink is the map defined IN THE satellite configuration
                  but for creating connections, we need the have the satellitemap of the Arbiter
        """
        self.arb_satmap = {
            "address": self.address,
            "port": self.port,
            "use_ssl": self.use_ssl,
            "hard_ssl_name_check": self.hard_ssl_name_check,
        }
        self.arb_satmap.update(satellitemap)

    def create_connection(self):
        self.con = HTTPClient(
            address=self.arb_satmap["address"],
            port=self.arb_satmap["port"],
            timeout=self.timeout,
            data_timeout=self.data_timeout,
            use_ssl=self.use_ssl,
            strong_ssl=self.hard_ssl_name_check,
        )
        self.uri = self.con.uri

    def put_conf(self, conf):
        if self.con is None:
            self.create_connection()

        # Maybe the connexion was not ok, bail out
        if not self.con:
            return False

        try:
            # pyro.set_timeout(self.con, self.data_timeout)
            self.con.get("ping")
            self.con.post("put_conf", {"conf": conf}, wait="long")
            # pyro.set_timeout(self.con, self.timeout)
            print "PUT CONF SUCESS", self.get_name()
            return True
        except HTTPExceptions, exp:
            self.con = None
            logger.error("Failed sending configuration for %s: %s" % (self.get_name(), str(exp)))
            return False
Beispiel #3
0
class SatelliteLink(Item):
    """SatelliteLink is a common Class for link to satellite for
    Arbiter with Conf Dispatcher.

    """
    # id = 0 each Class will have it's own id

    properties = Item.properties.copy()
    properties.update({
        'address':
        StringProp(default='localhost', fill_brok=['full_status']),
        'timeout':
        IntegerProp(default=3, fill_brok=['full_status']),
        'data_timeout':
        IntegerProp(default=120, fill_brok=['full_status']),
        'check_interval':
        IntegerProp(default=60, fill_brok=['full_status']),
        'max_check_attempts':
        IntegerProp(default=3, fill_brok=['full_status']),
        'spare':
        BoolProp(default=False, fill_brok=['full_status']),
        'manage_sub_realms':
        BoolProp(default=True, fill_brok=['full_status']),
        'manage_arbiters':
        BoolProp(default=False, fill_brok=['full_status'], to_send=True),
        'modules':
        ListProp(default=[''], to_send=True, split_on_coma=True),
        'polling_interval':
        IntegerProp(default=1, fill_brok=['full_status'], to_send=True),
        'use_timezone':
        StringProp(default='NOTSET', to_send=True),
        'realm':
        StringProp(default='',
                   fill_brok=['full_status'],
                   brok_transformation=get_obj_name_two_args_and_void),
        'satellitemap':
        DictProp(default={}, elts_prop=AddrProp, to_send=True, override=True),
        'use_ssl':
        BoolProp(default=False, fill_brok=['full_status']),
        'hard_ssl_name_check':
        BoolProp(default=True, fill_brok=['full_status']),
        'passive':
        BoolProp(default=False, fill_brok=['full_status'], to_send=True),
    })

    running_properties = Item.running_properties.copy()
    running_properties.update({
        'con':
        StringProp(default=None),
        'alive':
        BoolProp(default=True, fill_brok=['full_status']),
        'broks':
        StringProp(default=[]),

        # the number of failed attempt
        'attempt':
        StringProp(default=0, fill_brok=['full_status']),

        # can be network ask or not (dead or check in timeout or error)
        'reachable':
        BoolProp(default=False, fill_brok=['full_status']),
        'last_check':
        IntegerProp(default=0, fill_brok=['full_status']),
        'managed_confs':
        StringProp(default={}),
    })

    def __init__(self, *args, **kwargs):
        super(SatelliteLink, self).__init__(*args, **kwargs)

        self.arb_satmap = {'address': '0.0.0.0', 'port': 0}
        if hasattr(self, 'address'):
            self.arb_satmap['address'] = self.address
        if hasattr(self, 'port'):
            try:
                self.arb_satmap['port'] = int(self.port)
            except Exception:
                pass

    def set_arbiter_satellitemap(self, satellitemap):
        """
            arb_satmap is the satellitemap in current context:
                - A SatelliteLink is owned by an Arbiter
                - satellitemap attribute of SatelliteLink is the map
                  defined IN THE satellite configuration
                  but for creating connections, we need the have the satellitemap of the Arbiter
        """
        self.arb_satmap = {
            'address': self.address,
            'port': self.port,
            'use_ssl': self.use_ssl,
            'hard_ssl_name_check': self.hard_ssl_name_check
        }
        self.arb_satmap.update(satellitemap)

    def create_connection(self):
        self.con = HTTPClient(address=self.arb_satmap['address'],
                              port=self.arb_satmap['port'],
                              timeout=self.timeout,
                              data_timeout=self.data_timeout,
                              use_ssl=self.use_ssl,
                              strong_ssl=self.hard_ssl_name_check)
        self.uri = self.con.uri

    def put_conf(self, conf):
        if self.con is None:
            self.create_connection()

        # Maybe the connection was not ok, bail out
        if not self.con:
            return False

        try:
            self.con.get('ping')
            self.con.post('put_conf', {'conf': conf}, wait='long')
            print "PUT CONF SUCESS", self.get_name()
            return True
        except HTTPExceptions, exp:
            self.con = None
            self.configuration_errors.append(
                "Failed sending configuration for %s: %s" %
                (self.get_name(), str(exp)))
            return False
Beispiel #4
0
daemon=options.daemon

if daemon not in daemon_types:
    print 'CRITICAL - ', daemon, 'is not a Shinken daemon!'
    parser.print_help()
    raise SystemExit(CRITICAL)

port=options.portnum
if port==0:
    port=daemon_types[daemon]

con = None
try:
    con = HTTPClient(address=options.hostname, port=port,  timeout=options.timeout, data_timeout=options.data_timeout, use_ssl=options.ssl)
    result=con.get('ping')
except Exception, exp:
    print "CRITICAL : the %s is not reachable : (%s)." % (daemon,exp)
    raise SystemExit(CRITICAL)

if result:
   if result=='pong':
       if daemon != 'arbiter':
           try:
               result=con.get('have_conf')
           except Exception, exp:
               print "CRITICAL : the have_conf call to the %s failed : (%s)." % (daemon,exp)
               raise SystemExit(CRITICAL)

           if result:
               daemon_type = 'live'
daemon=options.daemon

if daemon not in daemon_types:
    print 'CRITICAL - ', daemon, 'is not a Shinken daemon!'
    parser.print_help()
    raise SystemExit(CRITICAL)

port=options.portnum
if port==0:
    port=daemon_types[daemon]

con = None
try:
    con = HTTPClient(address=options.hostname, port=port,  timeout=options.timeout, data_timeout=options.data_timeout, use_ssl=options.ssl)
    result=con.get('ping')
except Exception, exp:
    print "CRITICAL : the %s is not reachable : (%s)." % (daemon,exp)
    raise SystemExit(CRITICAL)

if result:
   if result=='pong':
       if daemon != 'arbiter':
           try:
               result=con.get('have_conf')
           except Exception, exp:
               print "CRITICAL : the have_conf call to the %s failed : (%s)." % (daemon,exp)
               raise SystemExit(CRITICAL)

           if result:
               daemon_type = 'live'