예제 #1
0
def do_report(result, flock, fdata):
    time.sleep(1)  # sometimes the function is called a sec too soon.
    # Get the time and date in human-readable form and UN*X-epoch...
    outDate = time.strftime('%Y-%m-%dT%H:%M:%S')
    outEpoch = int(time.strftime('%s'))
    # round to current minute to ease database JOINs
    outEpoch = outEpoch - (outEpoch % 60)
    # ident            = NODE + '@' + str(outEpoch)
    mf.lock(flock)
    with open(fdata, 'a') as f:
        f.write('{0}, {1}, {2}, {3}, {4}, {5}\n'.format(
            outDate, outEpoch, NODE, sda.id, result[0],
            sda.id + '@' + str(outEpoch)))
        f.write('{0}, {1}, {2}, {3}, {4}, {5}\n'.format(
            outDate, outEpoch, NODE, sdb.id, result[1],
            sdb.id + '@' + str(outEpoch)))
        f.write('{0}, {1}, {2}, {3}, {4}, {5}\n'.format(
            outDate, outEpoch, NODE, sdc.id, result[2],
            sdc.id + '@' + str(outEpoch)))
        f.write('{0}, {1}, {2}, {3}, {4}, {5}\n'.format(
            outDate, outEpoch, NODE, sdd.id, result[3],
            sdd.id + '@' + str(outEpoch)))
        f.write('{0}, {1}, {2}, {3}, {4}, {5}\n'.format(
            outDate, outEpoch, NODE, sde.id, result[4],
            sde.id + '@' + str(outEpoch)))
    mf.unlock(flock)
예제 #2
0
def do_markdown(flock, fdata):
  home              = os.path.expanduser('~')
  uname             = os.uname()

  fi = home + "/.kamstrupd.branch"
  with open(fi, 'r') as f:
    kamstrupbranch  = f.read().strip('\n')

  mf.lock(flock)
  shutil.copyfile(home + '/' + MYAPP + '/default.md', fdata)

  with open(fdata, 'a') as f:
    mf.syslog_trace("writing {0}".format(fdata), False, DEBUG)

    f.write('![A GNUplot image should be here: kamstrup11.png](img/kamstrup11.png)\n')
    f.write('![A GNUplot image should be here: kamstrup12.png](img/kamstrup12.png)\n')
    f.write('![A GNUplot image should be here: kamstrup13.png](img/kamstrup13.png)\n')

    # System ID
    f.write('!!! ')
    f.write(uname[0] + ' ' + uname[1] + ' ' + uname[2] + ' ' + uname[3] + ' ' + uname[4] + ' ' + platform.platform() + '  \n')

    # branch
    f.write('!!! kamstrupd   on: ' + kamstrupbranch + '\n\n')

  mf.unlock(flock)
예제 #3
0
def do_report(result, flock, fdata):
  # Get the time and date in human-readable form and UN*X-epoch...
  outDate  = time.strftime('%Y-%m-%dT%H:%M:%S')
  outEpoch = int(time.strftime('%s'))
  # round to current minute to ease database JOINs
  # outEpoch = outEpoch - (outEpoch % 60)
  result   = ', '.join(map(str, result))
  mf.lock(flock)
  mf.syslog_trace("   @: {0}s".format(outDate), False, DEBUG)
  with open(fdata, 'a') as f:
    f.write('{0}, {1}, {2}\n'.format(outDate, outEpoch, result))
  mf.unlock(flock)
예제 #4
0
def do_report(result, flock, fdata):
  time.sleep(1)   # sometimes the function is called a sec too soon.
  # Get the time and date in human-readable form and UN*X-epoch...
  outDate   = time.strftime('%Y-%m-%dT%H:%M:%S')
  outEpoch  = int(time.strftime('%s'))
  # round to current minute to ease database JOINs
  outEpoch  = outEpoch - (outEpoch % 60)
  result    = ', '.join(map(str, result))
  ident            = NODE + '@' + str(outEpoch)
  mf.syslog_trace(">>> ID : {0}  -  {1}".format(ident, outDate), False, DEBUG)
  mf.lock(flock)
  with open(fdata, 'a') as f:
    f.write('{0}, {1}, {2}, {3}, {4}\n'.format(outDate, outEpoch, NODE, result, ident))
  mf.unlock(flock)
예제 #5
0
def do_sql_data(flock, inicnfg, cnsql):
  mf.syslog_trace("============================", False, DEBUG)
  mf.syslog_trace("Pushing data to MySQL-server", False, DEBUG)
  mf.syslog_trace("============================", False, DEBUG)
  mf.unlock(flock)  # remove stale lock
  time.sleep(2)
  mf.lock(flock)
  # wait for all other processes to release their locks.
  count_internal_locks = 2
  while (count_internal_locks > 1):
    time.sleep(1)
    count_internal_locks = 0
    for fname in glob.glob(r'/tmp/' + MYAPP + '/*.lock'):
      count_internal_locks += 1
    mf.syslog_trace("{0} internal locks exist".format(count_internal_locks), False, DEBUG)
  # endwhile

  for inisect in inicnfg.sections():  # Check each section of the config.ini file
    errsql = False
    try:
      ifile = inicnfg.get(inisect, "resultfile")
      mf.syslog_trace(" < {0}".format(ifile), False, DEBUG)

      try:
        sqlcmd = []
        sqlcmd = inicnfg.get(inisect, "sqlcmd")
        mf.syslog_trace("   CMD : {0}".format(sqlcmd), False, DEBUG)

        data = mf.cat(ifile).splitlines()
        if data:
          for entry in range(0, len(data)):
            errsql = do_writesample(cnsql, sqlcmd, data[entry])
          # endfor
        # endif
      except configparser.NoOptionError:  # no sqlcmd
        mf.syslog_trace("*1* {0}".format(sys.exc_info()[1]), False, DEBUG)
    except configparser.NoOptionError:  # no ifile
      mf.syslog_trace("*2* {0}".format(sys.exc_info()[1]), False, DEBUG)

    try:
      if os.path.isfile(ifile) and not errsql:
        # IF resultfile exists AND SQL-job was successful or non-existing
        mf.syslog_trace("Deleting {0}".format(ifile), False, DEBUG)
        os.remove(ifile)
    except configparser.NoOptionError:  # no ofile
      mf.syslog_trace("*3* {0}".format(sys.exc_info()[1]), False, DEBUG)

  # endfor
  mf.unlock(flock)
예제 #6
0
def do_markdown(flock, fdata, hwdevice):
    home = os.path.expanduser('~')
    uname = os.uname()
    Tcpu = "(no T-sensor)"
    fcpu = "(no f-sensor)"
    mds = ""
    if os.path.isfile(hwdevice):
        fi = hwdevice
        with open(fi, 'r') as f:
            Tcpu = float(f.read().strip('\n')) / 1000

    if os.path.isfile('/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq'):
        fi = "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq"
        with open(fi, 'r') as f:
            fcpu = float(f.read().strip('\n')) / 1000
    fcpu_stats = str(subprocess.check_output(["cpufreq-info", "-sm"]), 'utf-8')

    fi = home + "/.lnxdiagd.branch"
    with open(fi, 'r') as f:
        lnxdiagdbranch = f.read().strip('\n')

    if os.path.isfile("/proc/mdstat"):
        mds = "-\n" + str(subprocess.check_output(["cat", "/proc/mdstat"]),
                          'utf-8')
    uptime = str(subprocess.check_output(["uptime"]), 'utf-8')
    # dfh               = str(subprocess.check_output(["df", "-h"]), 'utf-8')
    # freeh             = str(subprocess.check_output(["free", "-h"]), 'utf-8')
    # p1                = subprocess.Popen(["ps", "-e", "-o", "pcpu,args"],           stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    # p2                = subprocess.Popen(["cut", "-c", "-132"],   stdin=p1.stdout,  stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    # p3                = subprocess.Popen(["awk", "NR>2"],         stdin=p2.stdout,  stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    # p4                = subprocess.Popen(["sort", "-nr"],         stdin=p3.stdout,  stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    # p5                = subprocess.Popen(["head", "-10"],         stdin=p4.stdout,  stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    # ps, err            = p5.communicate()
    # psout             = str(ps, 'utf-8')

    mf.lock(flock)

    with open(fdata, 'w') as f:
        mf.syslog_trace("writing {0}".format(fdata), False, DEBUG)
        # YAML header
        f.write('---\n')
        f.write('title: ' + NODE + '\n')
        f.write('menu: ' + NODE + '\n')
        f.write('---\n')

        # HEADER
        f.write('# ' + NODE + '\n\n')

        # System ID
        f.write('!!! ')
        f.write(uname[0] + ' ' + uname[2] + ' ' + uname[3] + ' ' + uname[4] +
                ' ' + platform.platform() + '  \n')

        # lnxdiagd branch
        f.write('!!! lnxdiagd   on: ' + lnxdiagdbranch + '\n\n')

        # System Uptime
        f.write('### Server Uptime:  \n')
        f.write('!!! ')
        f.write(uptime)
        f.write('\n')

        # CPU temperature and frequency
        f.write('### Server Temperature:  \n')
        f.write('!! ' + str(Tcpu) + ' degC @ ' + str(fcpu) +
                ' MHz    stats: ' + fcpu_stats + '\n\n')
        f.write('### Server Graphs:  \n')
        if (hwdevice != "nohwdevice"):
            f.write(
                '![A GNUplot image should be here: day11.png](img/day11.png)\n'
            )
            # f.write('![A GNUplot image should be here: day11.png](img/day11.old.png)\n')
        f.write(
            '![A GNUplot image should be here: day12.png](img/day12.png)\n')
        f.write(
            '![A GNUplot image should be here: day14.png](img/day14.png)\n')
        f.write(
            '![A GNUplot image should be here: day13.png](img/day13.png)\n')
        f.write(
            '![A GNUplot image should be here: day15.png](img/day15.png)\n')
        if (NODE == "boson"):
            f.write(
                '![A GNUplot image should be here: day19.png](img/day19.png)\n'
            )

        # # Disk usage
        # f.write('## Disk Usage\n')
        # f.write(dfh)      # dfh comes with its own built-in '/n'
        if (NODE == "boson"):
            f.write('```\n')
            f.write(mds)  # mds comes with its own built-in '/n'
            f.write('```\n\n')

        if (NODE == "boson"):
            rbc_sda = sda.getdata('5')
            rbc_sdb = sdb.getdata('5')
            rbc_sdc = sdc.getdata('5')
            rbc_sdd = sdd.getdata('5')
            rbc_sde = sde.getdata('5')
            # ou_sda = sda.getdata('198')
            ou_sdb = sdb.getdata('198')
            ou_sdc = sdc.getdata('198')
            ou_sdd = sdd.getdata('198')
            ou_sde = sde.getdata('198')
            # disktemperature
            temperature_sda = sda.getdata('194')
            temperature_sdb = sdb.getdata('194')
            temperature_sdc = sdc.getdata('194')
            temperature_sdd = sdd.getdata('194')
            temperature_sde = sde.getdata('194')
            # disk power-on time
            pwron_time_a = sda.getdata('9')
            pwron_time_b = sdb.getdata('9')
            pwron_time_c = sdc.getdata('9')
            pwron_time_d = sdd.getdata('9')
            pwron_time_e = sde.getdata('9')
            # disk health
            health_sda = sda.gethealth()
            health_sdb = sdb.gethealth()
            health_sdc = sdc.gethealth()
            health_sdd = sdd.gethealth()
            health_sde = sde.gethealth()
            # Self-test info
            test_sda = sda.getlasttest()  # noqa
            test_sdb = sdb.getlasttest()
            test_sdc = sdc.getlasttest()
            test_sdd = sdd.getlasttest()
            test_sde = sde.getlasttest()
            # Disk info
            info_sda = sda.getinfo()
            info_sdb = sdb.getinfo()
            info_sdc = sdc.getinfo()
            info_sdd = sdd.getinfo()
            info_sde = sde.getinfo()
            f.write('```\n')
            f.write('SSD: ' + temperature_sda + ' || disk1: ' +
                    temperature_sdb + ' || disk2: ' + temperature_sdc +
                    ' || disk3: ' + temperature_sdd + ' || disk4: ' +
                    temperature_sde + ' [degC]\n')
            f.write('\n')
            f.write('---SSD---\n')
            f.write(' Name      : ' + info_sda + '\n')
            f.write(' PowerOn   : ' + pwron_time_a + '\n')
            # f.write(' Last test : ' + test_sda + '\n')
            if "PASSED" not in health_sda:
                f.write('             ' + health_sda + '\n')
            if not (rbc_sda == "0"):
                f.write('              Retired Block Count (5) = ' + rbc_sda +
                        '\n')

            f.write('---disk1---\n')
            f.write(' Name      : ' + info_sdb + '\n')
            f.write(' PowerOn   : ' + pwron_time_b + '\n')
            if "without" not in test_sdb:
                f.write(' Last test : ' + test_sdb + '\n')
            if "PASSED" not in health_sdb:
                f.write('             ' + health_sdb + '\n')
            if not (rbc_sdb == "0") or not (ou_sdb == "0"):
                f.write('              Retired Block Count (5) = ' + rbc_sdb +
                        ' - Offline Uncorrectable (198) = ' + ou_sdb + '\n')

            f.write('---disk2---\n')
            f.write(' Name      : ' + info_sdc + '\n')
            f.write(' PowerOn   : ' + pwron_time_c + '\n')
            if "without" not in test_sdc:
                f.write(' Last test : ' + test_sdc + '\n')
            if "PASSED" not in health_sdc:
                f.write('             ' + health_sdc + '\n')
            if not (rbc_sdc == "0") or not (ou_sdc == "0"):
                f.write('              Retired Block Count (5) = ' + rbc_sdc +
                        ' - Offline Uncorrectable (198) = ' + ou_sdc + '\n')

            f.write('---disk3---\n')
            f.write(' Name      : ' + info_sdd + '\n')
            f.write(' PowerOn   : ' + pwron_time_d + '\n')
            if "without" not in test_sdd:
                f.write(' Last test : ' + test_sdd + '\n')
            if "PASSED" not in health_sdd:
                f.write('             ' + health_sdd + '\n')
            if not (rbc_sdd == "0") or not (ou_sdd == "0"):
                f.write('              Retired Block Count (5) = ' + rbc_sdd +
                        ' - Offline Uncorrectable (198) = ' + ou_sdd + '\n')

            f.write('---disk4---\n')
            f.write(' Name      : ' + info_sde + '\n')
            f.write(' PowerOn   : ' + pwron_time_e + '\n')
            if "without" not in test_sde:
                f.write(' Last test : ' + test_sde + '\n')
            if "PASSED" not in health_sde:
                f.write('             ' + health_sde + '\n')
            if not (rbc_sde == "0") or not (ou_sde == "0"):
                f.write('              Retired Block Count (5) = ' + rbc_sde +
                        ' - Offline Uncorrectable (198) = ' + ou_sde + '\n')
            f.write(' ')
            f.write('```\n\n')

        # # Memory usage
        # f.write('## Memory Usage\n')
        # f.write('```\n')
        # f.write(freeh)    # freeh comes with its own built-in '/n'
        # f.write('```\n\n')

        # # Top 10 processes
        # f.write('## Top 10 processes:\n')
        # f.write('```\n')
        # f.write(psout)    # psout comes with its own built-in '/n'
        # f.write('```\n\n')

    mf.unlock(flock)