Skip to content

Commit

Permalink
Merge pull request #221 from netortik/platform2
Browse files Browse the repository at this point in the history
platform plugin init
  • Loading branch information
direvius committed May 12, 2016
2 parents fa0fcf4 + 1820297 commit acc7d92
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 1 deletion.
2 changes: 1 addition & 1 deletion yandextank/plugins/Monitoring/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def fixed_AES_new(key, *ls):
return client

def execute(self, cmd):
logger.info("Execute on %s: %s", self.host, cmd)
logger.debug("Execute on %s: %s", self.host, cmd)
with self.connect() as client:
_, stdout, stderr = client.exec_command(cmd)
output = stdout.read()
Expand Down
1 change: 1 addition & 0 deletions yandextank/plugins/Platform/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from plugin import *
89 changes: 89 additions & 0 deletions yandextank/plugins/Platform/plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
''' Module that collects remote system information '''

import logging
import getpass

from ...core.interfaces import AbstractPlugin
from ..Monitoring.collector import SecuredShell
from ..Phantom import PhantomPlugin

logger = logging.getLogger(__name__)


class Plugin(AbstractPlugin):
'''Plugin that collects remote system information'''
SECTION = "platform"

@staticmethod
def get_key():
return __file__

def __init__(self, core):
AbstractPlugin.__init__(self, core)
self.hosts = []
self.port = None
self.logfile = None
self.default_target = None
_echo_wrapper = lambda cmd: 'echo "====Executing: {cmd}"; {cmd}'.format(cmd=cmd)
cmds = {
"dpkg": "dpkg -l",
"uname": "uname -a",
"ulimit": "ulimit -a",
"os_identifier": "cat /etc/issue.net",
"uptime": "uptime",
"cpuinfo": "cat /proc/cpuinfo",
"meminfo": "cat /proc/meminfo",
"free": "free -m",
"mounts": "cat /proc/mounts",
"df": "df -h",
"ifconfig": "ifconfig -a",
"sysctl": "cat /etc/sysctl.conf",
"lsmod": "lsmod"
}
self.cmd = "%s" % ";\n".join([_echo_wrapper(cmd) for key, cmd in cmds.iteritems()])

def get_available_options(self):
return ["hosts", "port", "username", "timeout"]

def configure(self):
try:
hosts = self.get_option("hosts", "").strip()
if hosts:
self.hosts = hosts.split(" ")
self.port = int(self.get_option("port", 22))
self.username = self.get_option("username", getpass.getuser())
self.timeout = int(self.get_option("timeout", 3))
except:
logger.error('Exception trying to configure Platform plugin', exc_info=True)

self.logfile = self.core.mkstemp(".log", "platform_")
self.core.add_artifact_file(self.logfile)


def prepare_test(self):
try:
phantom = self.core.get_plugin_of_type(PhantomPlugin)
info = phantom.get_info()
if info:
if info.address and info.address not in self.hosts:
logger.debug("Adding platform check of default_target %s", info.address)
self.hosts.append(info.address)
except KeyError, ex:
logger.debug("Phantom plugin not found: %s", ex)
for host in self.hosts:
self.ssh = SecuredShell(host, self.port, self.username, self.timeout)
try:
out, errors, err_code = self.ssh.execute(self.cmd)
except Exception:
logger.warning("Failed to check remote system information at %s:%s", host, self.port)
logger.debug("Failed to check remote system information at %s:%s", host, self.port, exc_info=True)
else:
# logger.info('Remote system `%s` information: %s', host, out)
with open(self.logfile, 'w') as f:
f.write(out)
if errors:
logging.debug("[%s] error: '%s'", host, errors)


def is_test_finished(self):
return -1

0 comments on commit acc7d92

Please sign in to comment.