示例#1
0
def parse_varnishlog_args(args):
    """Expand the given list of (option, argument) 2-tuples, in a list of
    strings suitable for varnishapi.VarnishLog:

    [ ('i', 'ReqURL'), ('c', None), ('i', 'ReqMethod') ] ->
            [ '-i', 'ReqURL', 'c', '-i', 'ReqMethod' ]"""
    vapi = varnishapi.VarnishAPI()

    grouping = False
    parsed_args = []
    for switch, value in args:
        # eg: switch = "i", value = "ReqUrl"
        if switch == "i" and value not in vapi.VSL_tags_rev:
            raise Exception("Unknown Tag: %s" % value)

        if switch == "g":
            grouping = True

        parsed_args.append("-%s" % switch)
        if value:
            parsed_args.append(value)

    if not grouping:
        # Use request grouping by default. T137114
        parsed_args += ["-g", "request"]

    return parsed_args
def parse_varnishlog_args(args):
    """Expand the given list of (option, argument) 2-tuples, in a list of
    strings suitable for varnishapi.VarnishLog:

    [ ('i', 'ReqURL'), ('c', None), ('i', 'ReqMethod') ] ->
            [ '-i', 'ReqURL', 'c', '-i', 'ReqMethod' ]"""
    vapi = varnishapi.VarnishAPI()

    parsed_args = []
    for switch, value in args:
        # eg: switch = "i", value = "ReqUrl"
        if switch == "i" and value not in vapi.VSL_tags_rev:
            raise Exception("Unknown Tag: %s" % value)

        parsed_args.append("-%s" % switch)
        if value:
            parsed_args.append(value)

    return parsed_args
示例#3
0
	def attachVarnishAPI(self):
		self.vap = varnishapi.VarnishAPI(self.libvap)
示例#4
0
	def __init__(self, opts):
		#utils
		#buf -> trx 
		self.buf       = {}
		self.trx       = [{}]
		self.thr       = 10
		self.filter    = False
		self.mode_raw  = False
		self.o_json    = False
		self.log       = False
		self.mode_a    = False
		self.time      = int(time.time())
		self.last      = int(time.time())

		vops = ['-c', '-i', 'Length,RxHeader,RxUrl,TxStatus,ReqEnd,ReqStart,VCL_Call', '-I', '^([0-9]+$|Host:|/|[0-9\. ]+$|[a-z]+$)']

		for o,a in opts:
			if   o == '-i' and a.isdigit():
				self.thr = int(a)
			elif o == '-w':
				lg       = logging.handlers.WatchedFileHandler(a)
				lg.setLevel(logging.INFO)
				lg.setFormatter(logging.Formatter("%(message)s"))
				self.log = logging.getLogger()
				self.log.addHandler(lg)
				self.log.setLevel(logging.INFO)
			elif o == '-r':
				self.mode_raw = True
			elif o == '-a':
				self.mode_a   = True
			elif o == '-j':
				self.o_json = True
			elif o == '-n':
				vops += ['-n', a]
			elif o == '--start':
				start      = int(a)
				ns         = datetime.datetime.today().second
				if start > ns:
					wait   = start - ns
				elif start == ns:
					wait   = 0
				else:
					wait   = 60 - ns + start
				if wait > 0:
					self.time += wait
					self.last += wait
					time.sleep(wait)
			elif o == '-F':
				spl = a.split('@' ,2)
				tmp = [a, spl[0]]
				if len(spl) == 2:
					tmp.append(re.compile(spl[1]))
				else:
					tmp.append(False)
				if not self.filter: 
					self.filter = []
				self.filter.append(tmp)
		if self.mode_a and not self.filter:
			self.mode_a = False
			print "Disabled -a option. Bacause -F option is not specified."

		self.vap     = varnishapi.VarnishAPI(vops)
		self.vslutil = varnishapi.VSLUtil()
 def __init__(self):
     #connect varnishapi
     self.vap = varnishapi.VarnishAPI()
     #utils
     self.vslutil = varnishapi.VSLUtil()