Created
May 21, 2015 22:13
-
-
Save dougsyer/f13aa0a86642592a7508 to your computer and use it in GitHub Desktop.
Better linux os cmd modeller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ZenPacks/NWN/Events/modeler/plugins/NWN/cmd/centos_os_map.py | |
__version__ = '0.1' | |
from Products.DataCollector.plugins.CollectorPlugin import CommandPlugin | |
from Products.DataCollector.plugins.DataMaps import MultiArgs | |
import re | |
class centos_os_map(CommandPlugin): | |
""" | |
Sample output: | |
CentOS release 5.10 (Final) | |
Sometimes other stuff here | |
Linux IMAX-WEBINT-COL-001.inframax.local 2.6.18-371.12.1.el5 #1 SMP Wed Sep 3 16:22:34 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux | |
This works for rhel/centos 5 and 6 | |
""" | |
command = 'cat /etc/*release;uname -a' | |
def process(self, device, results, log): | |
"""Collect command-line information from this device""" | |
log.info("Processing the linux distribution and kernel version for for device %s", | |
device.id) | |
if not results: | |
log.warn("%s returned no results!", self.command) | |
return | |
log.debug("Results = %s", results.split('\n')) | |
res_splitter = results.split('\n') | |
try: | |
release_parts = res_splitter[0].split() | |
manuf = release_parts[0] | |
distrib_ver = " ".join(release_parts[2:]) | |
except: | |
log.info('Cound not determine linux distribution or kernel rev with this plugion') | |
return | |
# kernel version may not be in second line out output | |
kernel = re.compile(r'Linux\s.*?\s(.*?)\s') | |
for m in res_splitter: | |
if kernel.search(m): | |
kernel_rev = "Kernel - {0}".format(kernel.search(m).groups()[0]) | |
om = self.objectMap() | |
om.setOSProductKey = MultiArgs(" ".join([distrib_ver, kernel_rev]), manuf) | |
log.debug("setOSProductKey = %s", om.setOSProductKey) | |
return om |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment