Exemple #1
0
def cmd_httpstatus(ctx: jk_mediawiki.MWManagementCtx, cfg: dict, log,
                   bVerbose: bool) -> list:
    pids = []

    h = instantiateLocalUserServiceMgr(ctx, cfg, bVerbose)

    t = jk_console.SimpleTable()
    t.addRow("Service", "Status", "Main Process(es)").hlineAfterRow = True
    r = jk_console.Console.RESET

    nginxPIDs = h.getNGINXMasterProcesses(log)
    c = jk_console.Console.ForeGround.STD_GREEN if nginxPIDs else jk_console.Console.ForeGround.STD_DARKGRAY
    if nginxPIDs:
        pids.extend([x["pid"] for x in nginxPIDs])
        t.addRow("Local NGINX", "running",
                 str([x["pid"] for x in nginxPIDs])).color = c
    else:
        t.addRow("Local NGINX", "stopped", "-").color = c

    phpPIDs = h.getPHPFPMMasterProcesses(log)
    c = jk_console.Console.ForeGround.STD_GREEN if phpPIDs else jk_console.Console.ForeGround.STD_DARKGRAY
    if phpPIDs:
        pids.extend([x["pid"] for x in phpPIDs])
        t.addRow("Local PHP-FPM", "running",
                 str([x["pid"] for x in phpPIDs])).color = c
    else:
        t.addRow("Local PHP-FPM", "stopped", "-").color = c

    print()
    t.print()

    return pids
Exemple #2
0
async def main(ipAddresses: typing.Union[list, tuple]):
    ret = await jk_trioping.multiPing(ipAddresses)
    if parsedArgs.optionData["output-format"] == "json":
        jk_json.prettyPrint(ret)
    else:
        table = jk_console.SimpleTable()
        table.addRow("IP Address", "Ping").hlineAfterRow = True
        for key in sorted(ret.keys()):
            value = ret[key]
            table.addRow(key, "-" if value is None else (str(value) + " ms"))
        table.print()
    def dump(self, onlyLineNumbers: list = None):
        if onlyLineNumbers is not None:
            assert isinstance(onlyLineNumbers, (set, tuple, list))
            onlyLineNumbers = set(onlyLineNumbers)

        print("MediaWikiLocalSettingsFile")
        print("\t__bChanged: " + str(self.__changedFlag))
        print("\t__filePath: " + str(self.__filePath))

        if self.__data != None:
            table = jk_console.SimpleTable()

            if onlyLineNumbers:
                bFirst = True
                bLastWasPoints = False
                for (b, data) in self.__data:
                    if data.lineNo in onlyLineNumbers:
                        if bFirst:
                            bFirst = False
                            if data.lineNo > 1:
                                table.addRow("...", "...", "...")
                        table.addRow(
                            str(b), MediaWikiLocalSettingsFile.__getType(data),
                            str(data))
                        bLastWasPoints = False
                    else:
                        if not bLastWasPoints:
                            table.addRow("...", "...", "...")
                            bLastWasPoints = True
                        bFirst = False
            else:
                for (b, data) in self.__data:
                    table.addRow(str(b),
                                 MediaWikiLocalSettingsFile.__getType(data),
                                 str(data))
            print("\t__lines:")
            table.print(prefix="\t\t")
Exemple #4
0
#!/usr/bin/env python3

import os
import sys

import jk_mounting
import jk_json
import jk_console

mounter = jk_mounting.Mounter()

interesting = []
for mi in mounter.getMountInfos2(isRegularDevice=True, isNetworkDevice=True):
    interesting.append(mi)
interesting.sort(key=lambda x: x.mountPoint)

table = jk_console.SimpleTable()
headRow = table.addRow("mount point", "device", "file system", "mode")
headRow.hlineAfterRow = True

for mi in interesting:
    table.addRow(mi.mountPoint, mi.device, mi.fsType,
                 "r" if mi.isReadOnly else "rw")

print()
table.print()
print()
    def _getStatusOverview(
            self, wikiName: typing.Union[str, None], bWithDiskSpace: bool,
            bVerbose: bool,
            log: jk_logging.AbstractLogger) -> _StatusOverviewResult:
        wikiInsts = self.__wikiScanner.wikis

        pids = []

        t = jk_console.SimpleTable()
        rowData = [
            "Wiki", "MW Version", "SMW Version", "Status",
            "Last configuration", "Last use", "Cron Script Processes"
        ]
        if bWithDiskSpace:
            rowData.append("SizeRO")
            rowData.append("SizeRW")
        t.addRow(*rowData).hlineAfterRow = True
        r = jk_console.Console.RESET

        for wikiInst in wikiInsts:
            if wikiName:
                if wikiInst.name != wikiName:
                    continue

            blog = jk_logging.BufferLogger.create()
            try:
                with blog.descend("Checking wiki: " + wikiInst.name) as log2:
                    h = jk_mediawiki.MediaWikiLocalUserInstallationMgr(
                        self.__ctx, wikiInst, log2)
                    bIsRunning = h.isCronScriptRunning()
                    c = jk_console.Console.ForeGround.STD_GREEN if bIsRunning else jk_console.Console.ForeGround.STD_DARKGRAY
                    smVersion = h.getSMWVersion()
                    lastCfgTime = h.getLastConfigurationTimeStamp()
                    lastUseTime = h.getLastUseTimeStamp()
                    processInfos = h.getCronProcesses()
                    if processInfos:
                        processPIDs = [x["pid"] for x in processInfos]
                        pids.extend(processPIDs)
                    rowData = [
                        wikiInst.name,
                        str(h.getVersion()),
                        str(smVersion) if smVersion else "-",
                        "running" if bIsRunning else "stopped",
                        lastCfgTime.strftime("%Y-%m-%d %H:%M")
                        if lastCfgTime else "-",
                        lastUseTime.strftime("%Y-%m-%d %H:%M")
                        if lastUseTime else "-",
                        str(processPIDs) if bIsRunning else "-",
                    ]
                    if pids:
                        pids.extend(pids)
                    if bWithDiskSpace:
                        diskUsage = h.getDiskUsage()
                        rowData.append(_formatMBytes(diskUsage.ro / 1048576))
                        rowData.append(_formatMBytes(diskUsage.rw / 1048576))
                    t.addRow(*rowData).color = c
            except jk_logging.ExceptionInChildContextException as ee:
                pass

            if blog.stats.hasAtLeastWarning or bVerbose:
                blog.forwardTo(log)

        return _StatusOverviewResult(t, pids)
    def getExtensionMatrix(
            self, log: jk_logging.AbstractLogger) -> jk_console.SimpleTable:
        # str[] wikiNames
        # MediaWikiLocalUserInstallationMgr[] wikis
        # MediaWikiExtensionInfo[] wikiExtensionInfos

        wikiInsts = self.__wikiScanner.wikis
        wikiNames = [wikiInst.name for wikiInst in wikiInsts]
        wikis = [
            jk_mediawiki.MediaWikiLocalUserInstallationMgr(
                wikiInst, self.__userName, log) for wikiInst in wikiInsts
        ]
        wikiExtensionInfos = []

        allExtensionNames = set()
        for i, wikiName in enumerate(wikiNames):
            with log.descend("Scanning: {}".format(wikiName)) as log2:
                try:
                    if self.__bVerbose:
                        extInfos = []
                        for extInfo in wikis[i].getExtensionInfos(log2):
                            extInfos.append(extInfo)
                    else:
                        extInfos = list(wikis[i].getExtensionInfos())
                except jk_logging.ExceptionInChildContextException as ee:
                    log2.error(
                        "Stopping scanning for {} because of errors.".format(
                            wikiName))
                    extInfos = None
                except Exception as ee:
                    log2.error(ee)
                    log2.error(
                        "Stopping scanning for {} because of errors.".format(
                            wikiName))
                    extInfos = None

            wikiExtensionInfos.append(extInfos)
            if extInfos:
                for extInfo in extInfos:
                    allExtensionNames.add(extInfo.name)
        allExtensionNames = sorted(allExtensionNames)

        allExtensionsRowIndex = {
            name: (i + 2)
            for i, name in enumerate(allExtensionNames)
        }

        # prepare data matrix

        columnNames = [""] + allExtensionNames
        rowNames = [""] + wikiNames
        rowNames2 = [""] + [str(w.getVersion()) for w in wikis]
        _emptyList = ["-" for x in wikiNames]
        _emptyList2 = [0 for x in wikiNames]

        table = jk_console.SimpleTable()
        table.addRow(*rowNames)
        table.addRow(*rowNames2).hlineAfterRow = True
        table.row(0).color = jk_console.Console.ForeGround.STD_LIGHTCYAN
        table.row(1).color = jk_console.Console.ForeGround.STD_LIGHTCYAN

        rawTimeData = []

        for extensionName in allExtensionNames:
            dataRow = [extensionName] + _emptyList
            table.addRow(
                *
                dataRow)[0].color = jk_console.Console.ForeGround.STD_LIGHTCYAN
            rawTimeData.append(list(_emptyList2))

        # fill with raw data

        dtEpoch = datetime.datetime(1970, 1, 1)
        for _x, h in enumerate(wikis):
            colNo = _x + 1
            if wikiExtensionInfos[_x]:
                for extInfo in wikiExtensionInfos[_x]:
                    rowNo = allExtensionsRowIndex[extInfo.name]

                    s = str(extInfo.version) if extInfo.version else None
                    if extInfo.latestTimeStamp:
                        if s is None:
                            s = extInfo.latestTimeStamp.strftime("%Y-%m-%d")
                        rawTimeData[rowNo - 2][_x] = (extInfo.latestTimeStamp -
                                                      dtEpoch).total_seconds()

                    if s:
                        table.row(rowNo)[colNo].value = s
                    else:
                        table.row(rowNo)[colNo].value = "?"
            else:
                for rowNo in allExtensionsRowIndex.values():
                    table.row(rowNo)[colNo].value = "err"

        for _y in range(0, len(rawTimeData)):
            row = rawTimeData[_y]
            maxX = -1
            maxT2 = 0
            maxT = 0

            for _x in range(0, len(row)):
                if row[_x] > maxT:
                    maxT2 = maxT
                    maxT = row[_x]
                    maxX = _x
                cell = table.row(_y + 2)[_x + 1]
                if cell.value == "err":
                    cell.color = jk_console.Console.ForeGround.STD_RED
                else:
                    cell.color = jk_console.Console.ForeGround.STD_DARKGRAY

            for _x in range(0, len(row)):
                cell = table.row(_y + 2)[_x + 1]
                if (maxT > 0) and (row[_x] == maxT):
                    cell.color = jk_console.Console.ForeGround.STD_YELLOW
                elif (maxT2 > 0) and (row[_x] == maxT2):
                    cell.color = jk_console.Console.ForeGround.STD_LIGHTGRAY

        # return table

        return table