MSV FM

[email protected]: ~ $
Path : /usr/lib/fm-agent/plugins/
File Upload :
Current < : //usr/lib/fm-agent/plugins/uptime.py

import os
try: import json
except ImportError: import simplejson as json
import agent_util
import datetime
import time
import sys
from agent_util import float

class UptimePlugin(agent_util.Plugin):
    textkey = "uptime"
    label = "Machine Uptime"
    platform = sys.platform

    @classmethod
    def get_metadata(self, config):

        status = agent_util.SUPPORTED
        msg = None

        if 'sunos' in self.platform:
            psr = agent_util.which("psrinfo", exc=True)
            if not psr:
                status = agent_util.MISCONFIGURED
                msg = "Unable to collect uptime data, please make sure psrinfo is installed."
        else:
            who = agent_util.which("who", exc=True)
            if not who:
                status = agent_util.MISCONFIGURED
                msg = "Unable to collect uptime data, please make sure Who is installed."

        metadata = {
            "time_since_last_boot": {
                "label": "Time since last boot",
                "options": None,
                "status": status,
                "error_message": msg,
                "unit": "minutes"
            },
        }
        return metadata

    def check(self, textkey, data, config):
        if textkey == 'time_since_last_boot':
            lb = ''
            if 'sunos' in self.platform:
                psrinfo = agent_util.which("psrinfo", exc=True)
                retcode, output = agent_util.execute_command(psrinfo)
                lb = output.strip()
                lb = lb.split()[-2:]
                lb = ' '.join(lb)
                lb = datetime.datetime.strptime(lb, "%m/%d/%Y %H:%M:%S")

            elif "darwin" in self.platform:
                sysctl = agent_util.which("sysctl", exc=True)
                retcode, output = agent_util.execute_command("%s -n kern.boottime" % sysctl)
                fields = output.strip().split()
                return time.time() - int(fields[3].strip(","))

            elif 'aix' in self.platform:
                uptime = agent_util.which("uptime", exc=True)
                retcode, output = agent_util.execute_command(uptime)
                self.log.debug("####\n%s" % str(output))
                lb = re.sub(',|days|day','',str(output))
                self.log.debug("####\n%s" % str(lb))
                if "day" in output:
                    if "min" in output:
                        lb = re.split(' ',str(lb))[4:7]
                        lb = datetime.timedelta(days=int(lb[0]),minutes=int(lb[-1]))
                    elif "hr" in output:
                        lb = re.split(' ',str(lb))[4:7]
                        lb = datetime.timedelta(days=int(lb[0]),hours=int(lb[-1]))
                    else:
                        lb = re.split(' |:',str(lb))[5:10]
                        lb = datetime.timedelta(days=int(lb[0]),hours=int(lb[-2]),minutes=int(lb[-1]))

                else:
                    if "min" in output:
                        lb = re.split(' ',str(lb))[4]
                        lb = datetime.timedelta(minutes=int(lb))
                    elif "hr" in output:
                        lb = re.split(' ',str(lb))[4]
                        lb = datetime.timedelta(hours=int(lb))
                    else:
                        return 60

            else:
                uptime = open("/proc/uptime").read().split()[0]
                return int(float(uptime))

            ct = datetime.datetime.now()
            diff = ct - lb
            return int(diff.total_seconds())

        return 0


Bethany
Bethany
0%

THE FINEST HOTEL NEAR LAKE KIVU

The Perfect Base For You

Required fields are followed by *





EC1A68011

About Us

Delicious Interior With The Pinch Of Everything

Bethany Investment group is Presbyterian church in Rwanda(EPR) company that manage Hotel and Guest house in Karongi (Bethany Hotel), ISANO branch in GIKONDO(Kigali), Kiyovu branch(Kigali), AMIZERO branch(Nyagatare-East) and Gisenyi Branch(Rubavu).

Accomodation

Get a Comfortable Room
Feel The Comfort

Get a comfortable room and feel our hotel’s comfort. Bethany Hotel features a variety of fully furnished rooms with extra space, Executive rooms, Deluxe rooms with a beautiful lake view and garden space, Deluxe rooms, comfort rooms, family rooms and standard rooms at your service.

Standard Single

Services

We Provide Top Class Facility
Especially For You

Beach BBQ Party

Kick back on the beach& and enjoy our berbecue from our masterchef

Breakfast

Kick back at our hotels& enjoy our breakfast from our masterchef

Conference Hall

Kick back at our hotels& enjoy our conference halls from all bethany branches

Enjoy with your partner

Honeymoon Package

80%

Get In Touch

Don’t Miss Any Update

    +

    Search your Room

    Required fields are followed by *