Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 594657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:58:38+00:00 2026-05-13T15:58:38+00:00

I would like some feedback on my first Python script that makes use of

  • 0

I would like some feedback on my first Python script that makes use of OOP style. This is a Munin plugin that graphs average fan speed or average chassis temp depending on the name of the plugin (dell_fans, dell_temps).

An hour or so ago I submitted a procedural version of the fan speed plugin to stackoverflow to get help converting it to an OOP style. I then built off of that to combine the two scripts. Any feedback, suggestions, corrections would be very helpful. I would like to correct any misconceptions I may have before they cement.

Update: Modified to have common base class. Any other suggestions?

import sys
import subprocess

class Statistics(object):

    def __init__(self, command):
        self.command = command.split()

    def average(self):
        data = subprocess.Popen(self.command,stdout=subprocess.PIPE).stdout.readlines()

        count = total = 0
        for item in data:
            if "Reading" in item:
                # Extract variable length fan speed, without regex.
                total += float(item.split(":")[1].split()[0])
                count += 1
        # Sometimes omreport returns zero output if omsa services aren't started.
        if not count or not total:
            raise ValueError("No output from omreport. Is OMSA services started?")

        avg = (total / count)
        return avg

    def print_autoconfig(self):
        print "autoconfig goes here"


class Fanspeed(Statistics):

    def __init__(self, command):
        Statistics.__init__(self, command)

    def print_config(self):
        print "graph_title Average Fan Speed"
        print "graph_args --base 1000 -l 0"
        print "graph_vlabel speed (RPM)"
        print "graph_category Chassis"
        print "graph_info This graph shows the average speed of all fans"
        print "graph_period second"
        print "data.label speed"
        print "data.info Average fan speed for the five minutes."


class Temps(Statistics):

    def __init__(self, command):
        Statistics.__init__(self, command)

    def print_config(self):
        print "graph_title Average Temperature"
        print "graph_args --upper-limit 120 -l 0"
        print "graph_vlabel Celsius"
        print "graph_category Chassis"
        print "graph_info This graph shows the avg temp of all sensors."
        print "graph_period second"
        print "data.label temp"
        print "data.info Average chassis temperature for the five minutes."


if __name__ == '__main__':
    # Munin populates sys.argv[1] with "" (an empty argument), lets remove it.
    sys.argv = [x for x in sys.argv if x]

    if "fans" in sys.argv[0]:
        cmd = "/usr/sbin/omreport chassis fans"
        omdata = Fanspeed(cmd)
    elif "temps" in sys.argv[0]:
        cmd = "/usr/sbin/omreport chassis temps"
        omdata = Temps(cmd)
    else:
        print >> sys.stderr, "Change filename to dell_fans or dell_temps."
        sys.exit(1)

    if len(sys.argv) > 1:
        if sys.argv[1].lower() == "autoconfig":
            omdata.print_autoconfig()
        elif sys.argv[1].lower() == "config":
            omdata.print_config()
    else:
        try:
            average = omdata.average()
            print "data.value %s" % average
        except OSError, e:
            print >> sys.stderr, "Error running '%s', %s" % (cmd, e)
            sys.exit(1)
        except ValueError, e:
            # Sometimes omreport returns zero output if omsa services aren't started.
            print >> sys.stderr, 'Error: "omreport chassis fans" returned 0 output.'
            print >> sys.stderr, 'OMSA running? Try: "srvadmin-services.sh status".'
            sys.exit(1)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:58:38+00:00Added an answer on May 13, 2026 at 3:58 pm

    Is Temps a FanSpeed? That’s the litmus test for whether subclassing is appropriate (e.g. an elephant is an animal, a car is not an animal – so it might be appropriate to have a subclass of Animal which models an elephant, but not a subclass of Animal which models a car).

    It sounds like they’re modelling two different things – so yes, create a common base class for them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 385k
  • Answers 385k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If the call back page is in your domain, that… May 14, 2026 at 11:31 pm
  • Editorial Team
    Editorial Team added an answer Google has to discover your site -- it can't just… May 14, 2026 at 11:31 pm
  • Editorial Team
    Editorial Team added an answer Throw this code away. Seperate your html files from your… May 14, 2026 at 11:31 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.