From 4b9412ce0f18da79b71d3abbce343848dfa3a434 Mon Sep 17 00:00:00 2001 From: Jesse Jaggars Date: Tue, 28 Feb 2012 12:22:11 -0600 Subject: Removing many unused bits --- example_plugins/example.py | 58 ++++++++++++------------------------------- example_plugins/fsusage.py | 23 ----------------- example_plugins/release.py | 21 ---------------- example_plugins/runcommand.py | 45 --------------------------------- 4 files changed, 16 insertions(+), 131 deletions(-) delete mode 100644 example_plugins/fsusage.py delete mode 100644 example_plugins/release.py delete mode 100755 example_plugins/runcommand.py (limited to 'example_plugins') diff --git a/example_plugins/example.py b/example_plugins/example.py index d4356d1c..4b49e423 100755 --- a/example_plugins/example.py +++ b/example_plugins/example.py @@ -1,6 +1,3 @@ -## example.py -## An example sos plugin - ### This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or @@ -15,22 +12,22 @@ ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -import sos.plugintools +from sos.plugins import Plugin, RedHatPlugin -# Class name must be the same as file name and method names must not change -class example(sos.plugintools.PluginBase): - '''dummy example plugin''' +# the class name determines the plugin name +# if you want to override it simply provide a @classmethod name() +# that returns the name you want +class example(Plugin, RedHatPlugin): + '''This is the description for the example plugin''' # Plugin developers want to override setup() from which they will call - # addCopySpec() to collect files and collectExtOutPut() to collect programs + # addCopySpec() to collect files and collectExtOutput() to collect programs # output. - # If you want to go fancy you may also want to override diagnose(), - # analyze() and postproc(). Have a look at the PluginBase definition - # for details. # Add your options here, indicate whether they are slow to run, and set # whether they are enabled by default - # Options are python dictionaries that contain a short name, - # long description, speed, and whether they are enabled by default + # each option is a tuple of the following format: + # (name, description, fast or slow, default value) + # each option will be addressable like -k name=value optionList = [("init.d", 'Gathers the init.d directory', 'slow', 0), ('follicles', 'Gathers information about each follicle on every toe', 'slow', 0), ('color', 'Gathers toenail polish color', 'fast', 0)] @@ -45,39 +42,16 @@ class example(sos.plugintools.PluginBase): ''' # Here's how to copy files and directory trees self.addCopySpec("/etc/hosts") - # this one saves a file path to the copy for later analysis - # FIXME: Need to figure out how to do this - # self.fooFilePath = self.copyFileOrDir("/proc/cpuinfo") + + with open("/proc/cpuinfo") as f: + for line in f: + if "vendor_id" in line: + self.addAlert("Vendor ID string is: %s
\n" % line) # Here's how to test your options and execute if enabled if self.isOptionEnabled("init.d"): self.addCopySpec("/etc/init.d") # copies a whole directory tree # Here's how to execute a command - # you can save the path to the copied file for later analysis if desired - # FIXME: Need to figure out how to do this - self.psCmdDstFileName = self.collectExtOutput("/bin/ps -ef") - return + self.collectExtOutput("/bin/ps -ef") - def analyze(self): - ''' This is optional and need not be defined. - If you wish to perform some analysis on either files - that were gathered or on the output of commands, then save the filenames on the - destination file system when gathering that information in the setup() method - and use them here - ''' - # This is an example of opening and reading the output of a command that - # was run in the collect() method. Note that the output of the command is - # included in the report anyway - fd = open(self.fooFilePath) - lines = fd.readlines() - fd.close() - for line in lines: - if line.count("vendor_id"): - self.addCustomText("Vendor ID string is: %s
\n" % line) - # - # Alerts can optionally be generated, and will be included in the - # report automatically - # - self.addAlert("This is an alert") - return diff --git a/example_plugins/fsusage.py b/example_plugins/fsusage.py deleted file mode 100644 index 2532c5f7..00000000 --- a/example_plugins/fsusage.py +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env python - -### This program is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2 of the License, or -## (at your option) any later version. - -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. - -## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -import sos.plugintools - -# Class name must be the same as file name and method names must not change -class fsusage(sos.plugintools.PluginBase): - def setup(self): - self.psCmdDstFileName = self.collectExtOutput("/bin/df -al") - return diff --git a/example_plugins/release.py b/example_plugins/release.py deleted file mode 100644 index db4d7581..00000000 --- a/example_plugins/release.py +++ /dev/null @@ -1,21 +0,0 @@ -### This program is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2 of the License, or -## (at your option) any later version. - -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. - -## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -import sos.plugintools - -# Class name must be the same as file name and method names must not change -class release(sos.plugintools.PluginBase): - def setup(self): - self.addCopySpec("/etc/redhat-release") - return diff --git a/example_plugins/runcommand.py b/example_plugins/runcommand.py deleted file mode 100755 index df8951d2..00000000 --- a/example_plugins/runcommand.py +++ /dev/null @@ -1,45 +0,0 @@ -## runcommand.py -## An example plugin for sos - -### This program is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2 of the License, or -## (at your option) any later version. - -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. - -## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -import sos.plugintools - -# Class name must be the same as file name and method names must not change -class runcommand(sos.plugintools.PluginBase): - """This is a very simple example plugin that just runs one command in a shell. That - command could be a script supplied with your package which outputs information of interest - to support. When the script or command is run, stdout is collected and included in the - report generated by sosreport, and stderr is collected and copied into the sos log. - - This is useful for people who have minimal knowledge of python, who wish to write - collection tools in other languages, or who have existing tools. - - If your script or command generates output files that you want included in the sosreport - collection of files, include sosCp calls to include them. - - The only method required for this simple plugin is collect(). - - Your finished plugin should be included with your package and installed in python's - site-packages/sos/plugins/ directory - """ - def setup(self): - ''' Run a command. Output is automatically included in the report. - ''' - self.collectExtOutput("/path/to/my/script --myoption --anotheroption") - - # if (for example) that command created files /foo/bar/baz.txt and - # we want to include that in our report, we include the next line: - #self.pit.sosCp("/foo/bar/baz.txt") -- cgit