Beispiel #1
0
def kernel():
    _kernel = {}
    _kernel["name"] = providers.command("uname", "-s")
    _kernel["release"] = providers.command("uname", "-v")
    _kernel["machine"] = providers.command("uname", "-m")
    _kernel["version"] = providers.command("uname", "-r")

    return _kernel
Beispiel #2
0
def interfaces():
    _interfaces = {}

    current_interface = None

    for line in providers.command("ifconfig", "-a"):
        match = INTERFACE_RE.match(line)
        if match:
            match = match.groupdict()
            
            interface = match.pop('int')
            current_interface = _interfaces[interface] = match
        else:
            if not current_interface:
                continue
            
            for key, regex in INTERFACE_CONFIG_REGEXES.items():
                match = regex.match(line)

                if match:
                    match = match.groupdict()

                    if "inet" in key:
                        if not current_interface.get(key):
                            current_interface[key] = []
                        current_interface[key].append(match)
                    else:
                        current_interface.update(match)
                    break
    return _interfaces
Beispiel #3
0
def ps():
    _processes = []
    for process in providers.command("ps", "-ef"):
        match = PS_RE.search(process)
        if match:
            _processes.append(match.groupdict())
    return _processes
Beispiel #4
0
def mount():
    _mounts = {}
    for mount in providers.command("mount"):
        match = MOUNTS_RE.search(mount)
        if match:
            match = match.groupdict()
            match['options'] = str.split(match['options'], ', ')
            _mounts[match.pop('device')] = match
    return _mounts
Beispiel #5
0
def modules():
    def munge(k, v):
        if re.match(MEMADDR_RE_STR, v) or k == "refs":
            v = int(v, 0)

        return k, v

    _modules = {}
    for module in providers.command("kextstat", "-k", "-l"):
        match = KERNEL_MODULE_RE.search(module)
        if match:
            match = dict([munge(k, v) for k, v in match.groupdict().items()])
            _modules[match.pop('name')] = match
    return _modules
Beispiel #6
0
def df():
    def munge(k, v):
        if re.match("\d+", v):
            v = int(v)
            if "blocks" in k:
                k = re.sub("blocks", "kb", k)
                v = v / (1024 / _block_size)
        return k, v

    _df = providers.command("df")
    _block_size = int(BLOCK_SIZE_RE.search(_df[0]).group("block_size"))

    _mounts = {}
    for mount in _df:
        match = DF_RE.search(mount)
        if match:
            match = dict([munge(k, v) for k, v in match.groupdict().items()])
            _mounts[match.pop('device')] = match
    return _mounts
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import re

from pynpoint import providers

__module__ = str.join('.', (__package__, "platform"))

# todo(chris): Clean this up when daemonized.
__platform__ =  dict([str.split(l, ":\t") for l
                                          in providers.command(
                                                        "/usr/bin/sw_vers")])


@providers.provides(provider=__module__)
def platform():
    return __platform__["ProductName"]


@providers.provides(provider=__module__)
def platform_version():
    return __platform__["ProductVersion"]


@providers.provides(provider=__module__)
def platform_build():
    return __platform__["BuildVersion"]
Beispiel #8
0
def routes():
    _routes = {}

    for route in providers.command("netstat", "-rn"):
        if "default" in route:
Beispiel #9
0
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import datetime
import re
import time

from pynpoint import providers

__module__ = str.join(".", (__package__, "uptime"))

# todo(chris): Make this work when pynpoint is daemonized.
UPTIME_RE = re.compile("kern.boottime:.*\s+(?P<uptime_secs>\d+),")
m = UPTIME_RE.search(providers.command("sysctl", "kern.boottime"))
UPTIME = int(m.group("uptime_secs"))
CURR_TIME = time.time()


@providers.provides(provider=__module__)
def uptime_secs():
    """Exposes the number of seconds the box has been up."""
    return int(CURR_TIME - UPTIME)


@providers.provides(provider=__module__)
def uptime():
    """Exposes the current uptime of the box in human readable format."""
    cur_dt = datetime.datetime.fromtimestamp(CURR_TIME)
    upt_dt = datetime.datetime.fromtimestamp(UPTIME)