diff options
author | ndarshan <dnarayan@redhat.com> | 2014-03-17 12:21:42 +0530 |
---|---|---|
committer | Bala.FA <barumuga@redhat.com> | 2014-04-29 10:14:32 +0530 |
commit | 686b574d3c1e55a778088b58a1a2fc75ce72d280 (patch) | |
tree | 89e6335b46c42dcea1c66e80cd7500059856ffd5 /plugins/network.py | |
parent | fcf78fd752dd24a8bb8b0bf8f62e7ba7ec0aac55 (diff) |
plugins:Fix to handle sadf not accepting time range, test case addition
This patch handles the issue of sadf not accepting time range
when used with -x (xml output) option(seen in version 9.0.4).
Added unit-test for memory, cpu, swap, network plugins and
refactored them.
Change-Id: Ie7c2ecfbb38060f236a6faed606bce0aedd27d7a
Signed-off-by: ndarshan <dnarayan@redhat.com>
Reviewed-on: https://cuckoo.blr.redhat.com:8443/14
Reviewed-by: Bala FA <barumuga@redhat.com>
Tested-by: Bala FA <barumuga@redhat.com>
Diffstat (limited to 'plugins/network.py')
-rwxr-xr-x | plugins/network.py | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/plugins/network.py b/plugins/network.py new file mode 100755 index 0000000..d25c848 --- /dev/null +++ b/plugins/network.py @@ -0,0 +1,86 @@ +#!/usr/bin/python +# Copyright (C) 2014 Red Hat Inc +# +# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA +# + +import sadf +import argparse +from glusternagios import utils + +_sadfNetCommand = ["sadf", "-x", "--", "-n", "DEV"] + + +def parse_input(): + parser = argparse.ArgumentParser() + group = parser.add_mutually_exclusive_group() + group.add_argument("-e", "--exclude", action="append", + help="Parameters to be excluded") + group.add_argument("-i", "--include", action="append", + help="Parameters to be included") + sadf.add_common_args(parser) + args = parser.parse_args() + return args + + +def showNetStat(s, iface_list=None, list_type=None): + pl_op = {} + if not s: + pl_op["message"] = ("IFACE UNKNOWN") + pl_op['exit_status'] = utils.PluginStatusCode.UNKNOWN + return pl_op + devNames = [] + perfLines = [] + try: + for dev in s['network']['net-dev']: + if list_type == "exclude": + if dev['iface'] in iface_list: + continue + elif list_type == "include": + if dev['iface'] not in iface_list: + continue + devNames.append(dev['iface']) + perfLines.append("%s.rxpck=%s %s.txpck=%s %s.rxkB=%s %s.txkB=%s" + % (dev['iface'], dev['rxpck'], + dev['iface'], dev['txpck'], + dev['iface'], dev['rxkB'], + dev['iface'], dev['txkB'])) + except (KeyError, ValueError, TypeError) as e: + pl_op["message"] = "key: %s not found" % str(e) + pl_op["exit_status"] = utils.PluginStatusCode.UNKNOWN + return pl_op + + pl_op["message"] = ("IFACE OK: %s |%s" % (", ".join(devNames), + " ".join(perfLines))) + pl_op['exit_status'] = utils.PluginStatusCode.OK + return pl_op + +if __name__ == '__main__': + args = parse_input() + try: + st = sadf.getLatestStat(sadf.sadfExecCmd(_sadfNetCommand), + args.interval if args.interval else 1) + except (sadf.SadfCmdExecFailedException, + sadf.SadfXmlErrorException) as e: + print str(e) + exit(utils.PluginStatusCode.UNKNOWN) + if args.exclude: + d = showNetStat(st, args.exclude, "exclude") + elif args.include: + d = showNetStat(st, args.include, "include") + else: + d = showNetStat(st) + print d["message"] + exit(d['exit_status']) |