示例#1
0
def find_misbehaving_servers(db, fail_list):
  max_values = {
    'disk': '5.0',
    'load': '1.5',
    'delta': '300'
  }

  report = []

  if len(fail_list):
    # We log the failure in the stats log
    for station in fail_list:
      db['c'].execute('insert into stats (callsign) values(?)', (str(station), ))

    report.append("Failure: %s" % ' '.join(fail_list))

  misbehaving = db['c'].execute('select callsign, disk, load, last_record from stations where active = 1 and (disk > ? or last_record > ?)', (max_values['disk'], max_values['delta'])).fetchall()

  for row in misbehaving:
    report.append("  %s: disk:%s load:%s last:%s" % row)
 
  if len(misbehaving):
    report.append("Thresholds: %s" % json.dumps(max_values, indent=2))

  if len(report) and mail_config:
    if not isRoot:
      print ("You aren't root. This is probably a test machine. I'm not mailing")
    else:
      # Don't want any scripts to read this and harvest my email.
      email_to_use = 'kri%s@%soo.com' % ("stopolous", "yah")

      misc.send_email(config=mail_config, who=email_to_use, subject="server issue", body='<br>'.join(report), sender='Indycast Admin <*****@*****.**>')
      print("Issues found. Sending email to %s." % email_to_use)
    print('\n'.join(report))
示例#2
0
def find_misbehaving_servers(db, fail_list):
    max_values = {
        'disk': '3.8',
        'load': '0.9',
        'delta': '300',
        'plist': [4, 6]
    }

    report = []

    if len(fail_list):
        report.append("Failure: %s" % ' '.join(fail_list))

    misbehaving = db['c'].execute(
        'select callsign, disk, load, last_record from stations where active = 1 and (disk > ? or last_record > ?)',
        (max_values['disk'], max_values['delta'])).fetchall()

    for row in misbehaving:
        report.append("  %s: disk:%s load:%s last:%s" % row)

    if len(misbehaving):
        report.append("Thresholds: %s" % json.dumps(max_values, indent=2))

    if len(report) and mail_config:
        # Don't want any scripts to read this and harvest my email.
        email_to_use = 'kri%s@%soo.com' % ("stopolous", "yah")

        misc.send_email(config=mail_config,
                        who=email_to_use,
                        subject="server issue",
                        body='<br>'.join(report),
                        sender='Indycast Admin <*****@*****.**>')
        print '\n'.join(report)
        print "Issues found. Sending email to %s." % email_to_use
示例#3
0
文件: server_query.py 项目: EQ4/DRR
def find_misbehaving_servers(db, fail_list):
  max_values = {
    'disk': '3.8',
    'load': '0.9',
    'delta': '300',
    'plist': [ 4, 6 ]
  }

  report = []

  if len(fail_list):
    report.append("Failure: %s" % ' '.join(fail_list))

  misbehaving = db['c'].execute('select callsign, disk, load, last_record from stations where active = 1 and (disk > ? or last_record > ?)', (max_values['disk'], max_values['delta'])).fetchall()

  for row in misbehaving:
    report.append("  %s: disk:%s load:%s last:%s" % row)
 
  if len(misbehaving):
    report.append("Thresholds: %s" % json.dumps(max_values, indent=2))

  if len(report) and mail_config:
    # Don't want any scripts to read this and harvest my email.
    email_to_use = 'kri%s@%soo.com' % ("stopolous", "yah")

    misc.send_email(config=mail_config, who=email_to_use, subject="server issue", body='<br>'.join(report), sender='Indycast Admin <*****@*****.**>')
    print '\n'.join(report)
    print "Issues found. Sending email to %s." % email_to_use
示例#4
0
def find_requests_and_send_mail(config):
    os.chdir(os.path.dirname(os.path.realpath(__file__)))
    db = DB.connect(db_file='../db/main.db')
    now = time.time()
    what_we_be_done_with = db['c'].execute(
        'select * from reminders where end_time < %d' % now).fetchall()

    for row in DB.map(what_we_be_done_with, 'reminders', db=db):
        row['link'] = "http://indycast.net/%s/slices/%s_%d" % (
            row['station'],
            time.strftime("%Y%m%d%H%M",
                          time.gmtime(row['start_time'] - row['offset'] * 60)),
            (row['end_time'] - row['start_time']) / 60)

        if len(row['notes']):
            row['link'] += '/%s_on_%s' % (re.sub(
                '[^\w]', '_', row['notes']).strip('_'), row['station'])

        row['link'] += '.mp3'

        email = do_template(template_file='email_reminder_template.txt',
                            settings=row)
        res = misc.send_email(config=config,
                              who=row['email'],
                              subject=email['subject'],
                              body=email['body'])
        db['c'].execute('delete from reminders where id = %d' % row['id'])
        db['conn'].commit()

    return None
示例#5
0
def find_misbehaving_servers(db, fail_list):
    max_values = {'disk': '5.0', 'load': '1.5', 'delta': '300'}

    report = []
    subject = ''

    if len(fail_list):
        # We log the failure in the stats log
        for station in fail_list:
            db['c'].execute('insert into stats (callsign) values(?)',
                            (str(station), ))

        report.append("Failure: %s" % ' '.join(fail_list))
        subject += 'F: %s' % ' '.join(fail_list)

    misbehaving = db['c'].execute(
        'select callsign, disk, load, last_record from stations where active = 1 and (disk > ? or last_record > ?)',
        (max_values['disk'], max_values['delta'])).fetchall()

    for row in misbehaving:
        report.append("  %s: disk:%s load:%s last:%s" % row)

    if len(misbehaving):
        report.append("Thresholds: %s" % json.dumps(max_values, indent=2))

    if len(report):
        if not isRoot:
            print(
                "You aren't root. This is probably a test machine. I'm not mailing"
            )
        elif not mail_config:
            print("I'd like to email but I don't know how.")

        else:
            # Don't want any scripts to read this and harvest my email.
            email_to_use = 'kri%s@%soo.com' % ("stopolous", "yah")

            res = misc.send_email(config=mail_config,
                                  who=email_to_use,
                                  subject=subject,
                                  body='<br>'.join(report),
                                  sender='Indycast Admin <*****@*****.**>')
            print("Issues found. Sending email to %s." % email_to_use)
示例#6
0
def find_requests_and_send_mail(config):
  os.chdir(os.path.dirname(os.path.realpath(__file__)))
  db = DB.connect(db_file='../db/main.db')
  now = time.time()
  what_we_be_done_with = db['c'].execute('select * from reminders where end_time < %d' % now).fetchall()

  for row in DB.map(what_we_be_done_with, 'reminders', db=db):
    row['link'] = "http://indycast.net/%s/slices/%s_%d" % ( row['station'], time.strftime("%Y%m%d%H%M", time.gmtime(row['start_time'] - row['offset'] * 60)), (row['end_time'] - row['start_time']) / 60)

    if len(row['notes']):
      row['link'] += '/%s_on_%s' % (re.sub('[^\w]', '_', row['notes']).strip('_'), row['station'])

    row['link'] += '.mp3'

    email = do_template(template_file='email_reminder_template.txt', settings=row)
    res = misc.send_email(config=config, who=row['email'], subject=email['subject'], body=email['body'])
    db['c'].execute('delete from reminders where id = %d' % row['id'])
    db['conn'].commit()

  return None