(self, output, tags)
Parse out service checks from varnishadm.

        Example output:

            Backend b0 is Sick
            Current states  good:  2 threshold:  3 window:  5
            Average responsetime of good probes: 0.000000
            Oldest                                                    Newest
            ================================================================
            -------------------------------------------------------------444 Good IPv4
            -------------------------------------------------------------XXX Good Xmit
            -------------------------------------------------------------RRR Good Recv
            ----------------------------------------------------------HHH--- Happy
            Backend b1 is Sick
            Current states  good:  2 threshold:  3 window:  5
            Average responsetime of good probes: 0.000000
            Oldest                                                    Newest
            ================================================================
            ----------------------------------------------------------HHH--- Happy

        Example output (new output format):

            Backend name                   Admin      Probe
            boot.default                   probe      Healthy (no probe)
            boot.backend2                  probe      Healthy 4/4
              Current states  good:  4 threshold:  3 window:  4
              Average response time of good probes: 0.002504
              Oldest ================================================== Newest
              --------------------------------------------------------------44 Good IPv4
              --------------------------------------------------------------XX Good Xmit
              --------------------------------------------------------------RR Good Recv
              ------------------------------------------------------------HHHH Happy
Parse out service checks from varnishadm.
Parse out service checks from varnishadm .
def _parse_varnishadm(self, output, tags):
        """Parse out service checks from varnishadm.

        Example output:

            Backend b0 is Sick
            Current states  good:  2 threshold:  3 window:  5
            Average responsetime of good probes: 0.000000
            Oldest                                                    Newest
            ================================================================
            -------------------------------------------------------------444 Good IPv4
            -------------------------------------------------------------XXX Good Xmit
            -------------------------------------------------------------RRR Good Recv
            ----------------------------------------------------------HHH--- Happy
            Backend b1 is Sick
            Current states  good:  2 threshold:  3 window:  5
            Average responsetime of good probes: 0.000000
            Oldest                                                    Newest
            ================================================================
            ----------------------------------------------------------HHH--- Happy

        Example output (new output format):

            Backend name                   Admin      Probe
            boot.default                   probe      Healthy (no probe)
            boot.backend2                  probe      Healthy 4/4
              Current states  good:  4 threshold:  3 window:  4
              Average response time of good probes: 0.002504
              Oldest ================================================== Newest
              --------------------------------------------------------------44 Good IPv4
              --------------------------------------------------------------XX Good Xmit
              --------------------------------------------------------------RR Good Recv
              ------------------------------------------------------------HHHH Happy

        """
        # Process status by backend.
        backends_by_status = defaultdict(list)
        for line in output.split("\n"):
            backend, status, message = None, None, None
            # split string and remove all empty fields
            tokens = filter(None, line.strip().split(' '))
            tokens = [t for t in tokens]
            if len(tokens):
                if tokens == ['Backend', 'name', 'Admin', 'Probe']:
                    # skip the column headers that exist in new output format
                    continue
                # parse new output format
                # the backend name will include the vcl name
                # so split on first . to remove prefix
                elif len(tokens) >= 4 and tokens[1] in ['healthy', 'sick']:
                    # If the backend health was overridden, lets grab the
                    # overridden value instead of the probed health
                    backend = tokens[0].split('.', 1)[-1]
                    status = tokens[1].lower()
                elif len(tokens) >= 4 and tokens[1] == 'probe':
                    backend = tokens[0].split('.', 1)[-1]
                    status = tokens[2].lower()
                # Parse older Varnish backend output
                elif tokens[0] == 'Backend':
                    backend = tokens[1]
                    status = tokens[-1].lower()

                if tokens[0] == 'Current' and backend is not None:
                    try:
                        message = ' '.join(tokens[2:]).strip()
                    except Exception:
                        # If we can't parse a message still send a status.
                        self.log.exception('Error when parsing message from varnishadm')
                        message = ''

                if backend is not None:
                    backends_by_status[status].append((backend, message))

        for status, backends in iteritems(backends_by_status):
            check_status = BackendStatus.to_check_status(status)
            for backend, message in backends:
                service_checks_tags = ['backend:%s' % backend] + tags
                self.service_check(self.SERVICE_CHECK_NAME, check_status, tags=service_checks_tags, message=message)
def _parse_varnishadm ( self , output , tags ) : # Process status by backend. backends_by_status = defaultdict ( list ) for line in output . split ( "\n" ) : backend , status , message = None , None , None # split string and remove all empty fields tokens = filter ( None , line . strip ( ) . split ( ' ' ) ) tokens = [ t for t in tokens ] if len ( tokens ) : if tokens == [ 'Backend' , 'name' , 'Admin' , 'Probe' ] : # skip the column headers that exist in new output format continue # parse new output format # the backend name will include the vcl name # so split on first . to remove prefix elif len ( tokens ) >= 4 and tokens [ 1 ] in [ 'healthy' , 'sick' ] : # If the backend health was overridden, lets grab the # overridden value instead of the probed health backend = tokens [ 0 ] . split ( '.' , 1 ) [ - 1 ] status = tokens [ 1 ] . lower ( ) elif len ( tokens ) >= 4 and tokens [ 1 ] == 'probe' : backend = tokens [ 0 ] . split ( '.' , 1 ) [ - 1 ] status = tokens [ 2 ] . lower ( ) # Parse older Varnish backend output elif tokens [ 0 ] == 'Backend' : backend = tokens [ 1 ] status = tokens [ - 1 ] . lower ( ) if tokens [ 0 ] == 'Current' and backend is not None : try : message = ' ' . join ( tokens [ 2 : ] ) . strip ( ) except Exception : # If we can't parse a message still send a status. self . log . exception ( 'Error when parsing message from varnishadm' ) message = '' if backend is not None : backends_by_status [ status ] . append ( ( backend , message ) ) for status , backends in iteritems ( backends_by_status ) : check_status = BackendStatus . to_check_status ( status ) for backend , message in backends : service_checks_tags = [ 'backend:%s' % backend ] + tags self . service_check ( self . SERVICE_CHECK_NAME , check_status , tags = service_checks_tags , message = message )