File: //usr/local/qcloud/monitor/barad/plugin/collector/utils/conf_collect.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'hetiulin'
import commands
class FileCollect:
def __init__(self, path):
self._fpath = path
def getContent(self):
content = ''
try:
with open(self._fpath, 'r') as fd:
for line in fd.readlines():
line = line.lstrip()
if 0 < len(line) and not line.startswith('#'):
content += line
except IOError, e:
pass
return content
def test_FileCollect():
fc = FileCollect('/var/spool/cron/tabs/root')
print fc.getContent()
class CmdCollect:
def __init__(self, cmd):
self._cmd = cmd
def getOutput(self):
ret_code, ret_result = commands.getstatusoutput(self._cmd)
if 0 == ret_code:
return ret_result
else:
return ""
def test_CmdCollect():
cc = CmdCollect('ifconfig')
print cc.getOutput()
if __name__ == '__main__':
#test_FileCollect()
test_CmdCollect()