示例#1
0
def main(argv):
  pywrapfile.File.Init()
  config = entconfig.EntConfig(argv[0])
  if not config.Load():  sys.exit(__doc__)

  # Collect logs only if active
  state = install_utilities.install_state(config.var('VERSION'))
  if not state in [ 'ACTIVE', 'SERVE' ]:
    sys.exit(0)

  # NO collection for sitesearches:
  if config.var('SITESEARCH_INTERFACE'):
    sys.exit(0)

  # If I'm not a config replica I don't collect the logs..
  replicas = config.var('CONFIG_REPLICAS')
  crt_machine = E.getCrtHostName()
  if not crt_machine in replicas:
    logging.error('Not a replica')
    sys.exit(0)

  gws_log_dir = liblog.get_gws_log_dir(config)
  collect_dir = liblog.get_collect_dir(config)
  partition_dir = liblog.get_partition_dir(config)
  apache_dir = liblog.get_apache_dir(config)
  click_dir = liblog.get_click_dir(config)
  directory_map_file = liblog.get_directory_map_file(config)

  # in case cron job starts before adminrunner
  liblog.MakeDir(collect_dir)
  liblog.MakeDir(partition_dir)
  liblog.MakeDir(apache_dir)
  liblog.MakeDir(click_dir)

  # Collect Logs from machines
  all_machines = config.var('MACHINES')
  CollectLogs(all_machines, gws_log_dir, collect_dir)

  # Partition gwslogs by collections and convert to apache logs
  preprocess_logs.PartitionLogs(config)

  # Sanitize collection directory map
  coll_directory_map = liblog.CollectionDirectoryMap(directory_map_file)
  if coll_directory_map.sanitizeMap(partition_dir, apache_dir, click_dir):
    coll_directory_map.saveToDisk()

  # Send the OP logs to all machines
  SyncOpLogs(all_machines, config.var('LOGDIR'))

  logging.info('Done')
示例#2
0
  def __init__(self, cfg):
    self.cfg = cfg    # configurator object
    self.entConfig = cfg.globalParams
    # locks for updating the report lists
    self.logreplock = threading.RLock()
    self.logdir = self.cfg.getGlobalParam('LOGDIR')
    liblog.MakeDir(liblog.get_click_dir(self.entConfig))
    liblog.MakeDir(liblog.get_collect_dir(self.entConfig))
    liblog.MakeDir(liblog.get_apache_dir(self.entConfig))
    liblog.MakeDir(liblog.get_partition_dir(self.entConfig))
    liblog.MakeGoogleDir(self.entConfig, liblog.get_report_dir(self.entConfig))
    collection_dir_map_file = liblog.get_directory_map_file(self.entConfig)

    if not os.path.exists(collection_dir_map_file):
      open(collection_dir_map_file, 'w').close()  # a trick to touch a file.
    self.reportCount = { liblog.RAW_REPORT:  0,
                         liblog.SUMMARY_REPORT: 0, }
    self.sanitizeReportList(liblog.RAW_REPORT)
    self.sanitizeReportList(liblog.SUMMARY_REPORT)

    self.joblock = threading.Lock()
    self.runningJobs = {}
示例#3
0
def main(argv):
    argc = len(argv)

    if argc < 10:
        sys.exit(__doc__)

    config = entconfig.EntConfig(argv[0])
    if not config.Load(): sys.exit(__doc__)

    pywrapbase.InitGoogleScript('', [
        'foo',
        '--gfs_aliases=%s' % config.var("GFS_ALIASES"),
        '--bnsresolver_use_svelte=false', '--logtostderr'
    ], 0)
    gfile.Init()

    client = argv[1]
    date_fields = string.split(argv[2], '_')
    date_range = liblog.ParseDateRange(date_fields[0], date_fields[1:])

    withResults = argv[3]
    topCount = argv[4]
    diagnosticTerms = argv[5]

    html_file = argv[6]
    valid_file = argv[7]
    new_html_file = argv[8]
    new_valid_file = argv[9]

    if not date_range:
        sys.exit(__doc__)

    first_date, last_date, printable_date, file_date = date_range

    if last_date.as_int() < first_date.as_int():
        logging.fatal('invalid date range')

    gws_log_dir = liblog.get_gws_log_dir(config)
    collect_dir = liblog.get_collect_dir(config)
    partition_dir = liblog.get_partition_dir(config)
    directory_map_file = liblog.get_directory_map_file(config)

    # Collect logs first from all gws nodes and preprocess
    # logs to make sure logs are up to date.
    all_machines = config.var('MACHINES')
    collect_logs.CollectLogs(all_machines, gws_log_dir, collect_dir)
    preprocess_logs.PartitionLogs(config)

    gws_logs = liblog.FindClientLogFiles(partition_dir, directory_map_file,
                                         client, first_date, last_date)

    # note that collection (client) has been factored into gwslog_dir.
    result = CreateLogReport(config, printable_date, gws_logs,
                             config.var('MAIN_GOOGLE3_DIR'), withResults,
                             topCount, diagnosticTerms, html_file, valid_file,
                             new_html_file, new_valid_file)

    if result == liblog.FAILURE:
        logging.error('CreateLogReport Failed')

    sys.exit(result)
示例#4
0
def main(argv):
  argc = len(argv)

  if argc < 10:
    sys.exit(__doc__)

  config = entconfig.EntConfig(argv[0])
  if not config.Load():  sys.exit(__doc__)

  pywrapbase.InitGoogleScript('', ['foo',
          '--gfs_aliases=%s' % config.var("GFS_ALIASES"),
          '--bnsresolver_use_svelte=false',
          '--logtostderr'], 0)
  gfile.Init()

  client = argv[1]
  date_fields = string.split(argv[2], '_')
  date_range = liblog.ParseDateRange(date_fields[0], date_fields[1:])

  withResults = argv[3]
  topCount = argv[4]
  diagnosticTerms = argv[5]

  html_file = argv[6]
  valid_file = argv[7]
  new_html_file = argv[8]
  new_valid_file = argv[9]

  if not date_range:
    sys.exit(__doc__)

  first_date, last_date, printable_date, file_date = date_range

  if last_date.as_int() < first_date.as_int():
    logging.fatal('invalid date range')

  gws_log_dir = liblog.get_gws_log_dir(config)
  collect_dir = liblog.get_collect_dir(config)
  partition_dir = liblog.get_partition_dir(config)
  directory_map_file = liblog.get_directory_map_file(config)

  # Collect logs first from all gws nodes and preprocess
  # logs to make sure logs are up to date.
  all_machines = config.var('MACHINES')
  collect_logs.CollectLogs(all_machines, gws_log_dir, collect_dir)
  preprocess_logs.PartitionLogs(config)

  gws_logs = liblog.FindClientLogFiles(partition_dir, directory_map_file,
                                       client, first_date, last_date)

  # note that collection (client) has been factored into gwslog_dir.
  result = CreateLogReport(config, printable_date, gws_logs,
                           config.var('MAIN_GOOGLE3_DIR'),
                           withResults, topCount, diagnosticTerms,
                           html_file, valid_file,
                           new_html_file, new_valid_file)

  if result == liblog.FAILURE:
    logging.error('CreateLogReport Failed')

  sys.exit(result)
示例#5
0
def main(argv):
  argc = len(argv)

  if argc < 6:
    sys.exit(__doc__)

  config = entconfig.EntConfig(argv[0])
  if not config.Load():
    sys.exit(__doc__)

  pywrapbase.InitGoogleScript('', ['foo',
          '--gfs_aliases=%s' % config.var("GFS_ALIASES"),
          '--bnsresolver_use_svelte=false',
          '--logtostderr'], 0)
  gfile.Init()

  client = argv[1]
  date_arg = argv[2]
  html_file = argv[3]
  valid_file = argv[4]
  new_valid_file = argv[5]

  # extract tag and date_range from command line args
  date_fields = string.split(date_arg, '_')
  date_range = liblog.ParseDateRange(date_fields[0], date_fields[1:])

  if not date_range:
    sys.exit(__doc__)

  first_date, last_date, printable_date, file_date = date_range

  if last_date.as_int() < first_date.as_int():
    sys.exit(__doc__)

  gws_log_dir = liblog.get_gws_log_dir(config)
  click_dir = liblog.get_click_dir(config)
  collect_dir = liblog.get_collect_dir(config)
  apache_dir = liblog.get_apache_dir(config)
  directory_map_file = liblog.get_directory_map_file(config)

  # we need to collect logs first from all gws nodes and preprocess
  # logs first to make sure logs are up to date.
  all_machines = config.var('MACHINES')
  collect_logs.CollectLogs(all_machines, gws_log_dir, collect_dir)
  preprocess_logs.PartitionLogs(config)

  # make a vector of Log objects for all apache_logs and click_logs matching
  # the given date range and client.
  apache_logs = liblog.FindClientLogFiles(apache_dir, directory_map_file,
                                          client, first_date, last_date)
  click_logs = liblog.FindClientLogFiles(click_dir, directory_map_file,
                                          client, first_date, last_date)

  # If we have valid file and report file, we check to see if the data in
  # apache_dir has been changed and if the report is still valid.
  if (gfile.Exists(html_file) and gfile.Exists(valid_file) and
      liblog.checkValid(html_file, valid_file, apache_logs)):
    logging.info('%s still valid.' % html_file)
    sys.exit(liblog.STILL_VALID)

  # if there is no valid report, we create a new one
  DumpApacheAndClickLogs(apache_logs, click_logs)
  if not liblog.makeValid(new_valid_file, apache_logs):
    logging.error('Error validating %s' % html_file)
    sys.exit(liblog.FAILURE)

  logging.info('done apache_log, new_valid_file: %s' % new_valid_file)
  sys.exit(liblog.SUCCESS)
示例#6
0
def main(argv):
    argc = len(argv)

    if argc < 6:
        sys.exit(__doc__)

    config = entconfig.EntConfig(argv[0])
    if not config.Load():
        sys.exit(__doc__)

    pywrapbase.InitGoogleScript('', [
        'foo',
        '--gfs_aliases=%s' % config.var("GFS_ALIASES"),
        '--bnsresolver_use_svelte=false', '--logtostderr'
    ], 0)
    gfile.Init()

    client = argv[1]
    date_arg = argv[2]
    html_file = argv[3]
    valid_file = argv[4]
    new_valid_file = argv[5]

    # extract tag and date_range from command line args
    date_fields = string.split(date_arg, '_')
    date_range = liblog.ParseDateRange(date_fields[0], date_fields[1:])

    if not date_range:
        sys.exit(__doc__)

    first_date, last_date, printable_date, file_date = date_range

    if last_date.as_int() < first_date.as_int():
        sys.exit(__doc__)

    gws_log_dir = liblog.get_gws_log_dir(config)
    click_dir = liblog.get_click_dir(config)
    collect_dir = liblog.get_collect_dir(config)
    apache_dir = liblog.get_apache_dir(config)
    directory_map_file = liblog.get_directory_map_file(config)

    # we need to collect logs first from all gws nodes and preprocess
    # logs first to make sure logs are up to date.
    all_machines = config.var('MACHINES')
    collect_logs.CollectLogs(all_machines, gws_log_dir, collect_dir)
    preprocess_logs.PartitionLogs(config)

    # make a vector of Log objects for all apache_logs and click_logs matching
    # the given date range and client.
    apache_logs = liblog.FindClientLogFiles(apache_dir, directory_map_file,
                                            client, first_date, last_date)
    click_logs = liblog.FindClientLogFiles(click_dir, directory_map_file,
                                           client, first_date, last_date)

    # If we have valid file and report file, we check to see if the data in
    # apache_dir has been changed and if the report is still valid.
    if (gfile.Exists(html_file) and gfile.Exists(valid_file)
            and liblog.checkValid(html_file, valid_file, apache_logs)):
        logging.info('%s still valid.' % html_file)
        sys.exit(liblog.STILL_VALID)

    # if there is no valid report, we create a new one
    DumpApacheAndClickLogs(apache_logs, click_logs)
    if not liblog.makeValid(new_valid_file, apache_logs):
        logging.error('Error validating %s' % html_file)
        sys.exit(liblog.FAILURE)

    logging.info('done apache_log, new_valid_file: %s' % new_valid_file)
    sys.exit(liblog.SUCCESS)