diff options
author | sconklin <sconklin@ef72aa8b-4018-0410-8976-d6e080ef94d8> | 2006-07-12 19:17:06 +0000 |
---|---|---|
committer | sconklin <sconklin@ef72aa8b-4018-0410-8976-d6e080ef94d8> | 2006-07-12 19:17:06 +0000 |
commit | b7e0351d69f561d2c25878dc5269bdeb290ed059 (patch) | |
tree | 35910635986055e7ca9cf7632158b9e205a7dc00 /src/example_plugins | |
parent | 8521ca3b4db9775c09ae29af336abba99e939a2b (diff) | |
download | sos-b7e0351d69f561d2c25878dc5269bdeb290ed059.tar.gz |
Initial import, moved project from internal server to 108
git-svn-id: svn+ssh://svn.fedorahosted.org/svn/sos/trunk@5 ef72aa8b-4018-0410-8976-d6e080ef94d8
Diffstat (limited to 'src/example_plugins')
-rwxr-xr-x | src/example_plugins/example.py | 108 | ||||
-rw-r--r-- | src/example_plugins/fsusage.py | 23 | ||||
-rw-r--r-- | src/example_plugins/release.py | 23 | ||||
-rwxr-xr-x | src/example_plugins/runcommand.py | 60 | ||||
-rwxr-xr-x | src/example_plugins/template.py | 104 |
5 files changed, 318 insertions, 0 deletions
diff --git a/src/example_plugins/example.py b/src/example_plugins/example.py new file mode 100755 index 00000000..bf461c44 --- /dev/null +++ b/src/example_plugins/example.py @@ -0,0 +1,108 @@ +#!/usr/bin/env python + +## example.py +## An example sos plugin + +## Copyright (C) 2006 Steve Conklin <sconklin@redhat.com> + +### 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 example(sos.plugintools.PluginBase): + """This is an example plugin for sos. Plugins gather, analyze, and report on various aspects + of system operation that are of interest. plugins are based on the PluginBase class, which + you should inspect if you wish to override any methods in your plugin. The methods of use + to plugin developers are: + collect() - use the functions sosCp and sosRunExe to gether information + analyze() - perform any special analysis you require beyond just saving the + information gathered by collect(). Use sosAlert() and sosAddCustomText() + to add information to the report. + report() - override this method if you wish to replace the default reporting + + All plugins will use collect(), some will use analyze(), few will override report() + """ + optionList = [] + copiedFiles = [] + copiedDirs = [] + executedCommands = [] + alerts = [] + customText = "" + cInfo = None + piName = None + optNames = [] + optParms = [] + + # Add your options here, indicate whether they are slow to run, and set whether they are enabled by default + # Options are dictionaries that conatin a short name, long desc, speed, and whether they are enabled by default + optionList = [("init.d", 'Gathers the init.d directory', 'slow', 0), + ('Option 2', 'Gathers information about each follicle on every toe', 'slow', 0), + ('Option 3', 'Gathers toenail polish color', 'fast', 0)] + + def collect(self): + ''' First phase - Collect all the information we need. + Directories are copied recursively. arbitrary commands may be + executed using the susRunExe method. Information is automatically saved, and + links are presented in the report to each file or directory which has been + copied to the saved tree. Also, links are provided to the output from each command. + ''' + # Here's how to copy files and directory trees + self.copyFileOrDir("/etc/hosts") + # this one saves a file path to the copy for later analysis + self.fooFilePath = self.copyFileOrDir("/proc/cpuinfo") + + # Here's how to test your options and execute if enabled + if self.isOptionEnabled("init.d"): + self.copyFileOrDir("/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 + self.psCmdDstFileName = self.runExe("/bin/ps -ef") + return + + 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 collect() 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 <br>\n" % line) + # + # Alerts can optionally be generated, and will be included in the + # report automatically + # + self.addAlert("This is an alert") + return + +# def report(self): +# """ Usually, this doesn't even need to be defined, and you can inherit the +# base class, unless you want to replace what sosGetResults() +# does with your own custom report generator. If you are going to do that, have a good +# look at that method to see what it does. Custom text and alerts can still be added +# here using sosAddCustomText() and sosAddAlert() +# This method returns html that will be included inline in the report +# """ + + diff --git a/src/example_plugins/fsusage.py b/src/example_plugins/fsusage.py new file mode 100644 index 00000000..898aaa12 --- /dev/null +++ b/src/example_plugins/fsusage.py @@ -0,0 +1,23 @@ +#!/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 collect(self): + self.psCmdDstFileName = self.runExe("/bin/df -al") + return diff --git a/src/example_plugins/release.py b/src/example_plugins/release.py new file mode 100644 index 00000000..8ef395b5 --- /dev/null +++ b/src/example_plugins/release.py @@ -0,0 +1,23 @@ +#!/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 release(sos.plugintools.PluginBase): + def collect(self): + self.copyFileOrDir("/etc/redhat-release") + return diff --git a/src/example_plugins/runcommand.py b/src/example_plugins/runcommand.py new file mode 100755 index 00000000..fa16020e --- /dev/null +++ b/src/example_plugins/runcommand.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python + +## runcommand.py +## An example plugin for sos + +## Copyright (C) 2006 Steve Conklin <sconklin@redhat.com> + +### 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 + """ + optionList = [] + copiedFiles = [] + copiedDirs = [] + executedCommands = [] + alerts = [] + customText = "" + cInfo = None + piName = None + optNames = [] + optParms = [] + + def collect(self): + ''' Run a command. Output is automatically included in the report. + ''' + self.runExe("/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") diff --git a/src/example_plugins/template.py b/src/example_plugins/template.py new file mode 100755 index 00000000..f8ed0e35 --- /dev/null +++ b/src/example_plugins/template.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python + +## template.py +## A template for sos plugins + +## Copyright (C) 2006 Steve Conklin <sconklin@redhat.com> + +### 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 template(sos.plugintools.PluginBase): + """This is a template plugin for sos. Plugins gather, analyze, and report on various aspects + of system operation that are of interest. plugins are based on the PluginBase class, which + you should inspect if you wish to override any methods in your plugin. The methods of use + to plugin developers are: + collect() - use the functions sosCp and sosRunExe to gether information + analyze() - perform any special analysis you require beyond just saving the + information gathered by collect(). Use sosAlert() and sosAddCustomText() + to add information to the report. + report() - override this method if you wish to replace the default reporting + + All plugins will use collect(), some will use analyze(), few will override report() + """ + + # Add your options here, indicate whether they are slow to run, and set whether they are enabled by default + # Options are dictionaries that conatin a short name, long desc, speed, and whether they are enabled by default + optionList = [("init.d", 'Gathers the init.d directory', 'slow', 0), + ('Option 2', 'Gathers information about each follicle on every toe', 'slow', 0), + ('Option 3', 'Gathers toenail polish color', 'fast', 0)] + + def collect(self): + ''' First phase - Collect all the information we need. + Directories are copied recursively. arbitrary commands may be + executed using the susRunExe method. Information is automatically saved, and + links are presented in the report to each file or directory which has been + copied to the saved tree. Also, links are provided to the output from each command. + ''' + # For this example, we use files created in our build test directory. Edit the + # following line after running the maketesttree.sh script + testdir = "/home/sconklin/src/sos/tests/tree/" + self.copyFileOrDir(testdir + "absdirlink") + self.copyFileOrDir(testdir + "bar") + + # Here's how to test your options and execute if enabled + if self.isOptionEnabled("init.d"): + self.copyFileOrDir("/etc/init.d") + self.copyFileOrDir(testdir + "abslink") + # you can save the path to the copied file for later analysis if desired + self.fooFilePath = self.copyFileOrDir(testdir + "abslink2") + self.copyFileOrDir(testdir + "abslink3") + self.psCmdDstFileName = self.runExe("/bin/ps -ef") + return + + 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 collect() 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.psCmdDstFileName) + lines = fd.readlines() + fd.close() + procs = 0 + for line in lines: + # can perform analysis here - This is a dumb example, but + # shows how to add customized text to output + if line.count("sconkli"): + procs = procs + 1 + self.addCustomText("sconklin has %d processes running <br>\n" % procs) + # + # Alerts can optionally be generated, and will be included in the + # report automatically + # + self.addAlert("This is an alert") + return + +# def report(self): +# """ Usually, this doesn't even need to be defined, and you can inherit the +# base class, unless you want to replace what sosGetResults() +# does with your own custom report generator. If you are going to do that, have a good +# look at that method to see what it does. Custom text and alerts can still be added +# here using sosAddCustomText() and sosAddAlert() +# This method returns html that will be included inline in the report +# """ + + |