linux监控windos神器,linux通不过WMI连接windos,linux下WMI安装

alex 技术分享 监控文档1 阅读模式

本脚本是转发,为自动在linux下安装wmi,连接windos神器。需要安装的电脑上可以连接internet,如地址被墙,请自己找梯。
后续会根据脚本在发布一篇离线安装方法,
linux通过wmi连接windos服务器,linux监控windos服务器

#!/usr/bin/env python

# Script for installing WMI prerequisites
#
# Copyright (c) 2011 Nagios Enterprises, LLC.  All rights reserved.

import subprocess
import optparse
import re
import os
import tarfile
import sys
import yum

usrID = os.getuid()

if usrID != 0:
print("user ID not equal to 0.....")
print("This script must be run as root")
sys.exit()

#query GetOptLongVersion number
checkGetOptLong = """perl -MGetopt::Long -e 'print "$Getopt::Long::VERSION\n"'"""
getOptLongVer = subprocess.Popen(checkGetOptLong, shell=True, stdout=subprocess.PIPE)
getOptLongVer = (getOptLongVer.stdout.read().strip())

def installer(installcmds):
count = 0
for i in installcmds:
count+=1
print "installing..."
subprocess.call(i, shell=True)
return

def installGetOptLong(getOptLongVer):
try:
getOptLongVer = float(getOptLongVer)
except:
getOptLongVer = 0
if getOptLongVer < 2.38:
os.system("wget -c http://assets.nagios.com/downloads/nagiosxi/packages/Getopt-Long-2.38.tar.gz")
tarball = tarfile.open("Getopt-Long-2.38.tar.gz")
tarball.extractall(".")
os.chdir('./Getopt-Long-2.38')
perlMake = """perl Makefile.PL"""
perlMakeTest = """make all test"""
perlMakeInstall = """make install"""
getOptLong = [perlMake, perlMakeTest, perlMakeInstall]
installer(getOptLong)
os.chdir('../')

def installWmic():
archType = os.uname()[-1]
if archType == 'x86_64':
package = "wmic_1.3.13_static_64bit.tar.gz"
yuminstall = """yum install perl-DateTime perl-Config-IniFiles perl-List-MoreUtils -y"""
else:
yuminstall = """yum install perl-DateTime perl-Config-IniFiles perl-List-MoreUtils elf glibc.i686 glibc-devel.i686 cyrus-sasl-lib.i686 libcgroup-pam.i686 pam.i686 popt.i686 -y"""
package = "wmic_1.3.13_static_i386.tar.gz"
if os.path.exists(package) == False:
os.system("wget -c https://assets.nagios.com/downloads/nagiosxi/agents/" + package)
tarball = tarfile.open(package)
tarball.extractall("/")
if os.path.exists('/usr/bin/wmic') == True:
os.rename("/usr/bin/wmic", "/usr/bin/wmic.old")
os.symlink("/usr/local/bin/wmic", "/usr/bin/wmic")
subprocess.call(yuminstall, shell=True)
def _extractall(self, path=".", members=None):
"""Fallback extractall method for TarFile, in case it doesn't have its own."""

import copy
import operator

directories = []

if members is None:
members = self

for tarinfo in members:
if tarinfo.isdir():
# Extract directories with a safe mode.
directories.append(tarinfo)
tarinfo = copy.copy(tarinfo)
tarinfo.mode = 0700
self.extract(tarinfo, path)

# Reverse sort directories.
directories.sort(lambda a, b: cmp(a.name, b.name))
directories.reverse()

# Set correct owner, mtime and filemode on directories.
for tarinfo in directories:
dirpath = os.path.join(path, tarinfo.name)
try:
self.chown(tarinfo, dirpath)
self.utime(tarinfo, dirpath)
self.chmod(tarinfo, dirpath)
except tarfile.ExtractError, e:
if self.errorlevel > 1:
raise
else:
self._dbg(1, "tarfile: %s" % e)

if not hasattr(tarfile.TarFile, 'extractall'):
tarfile.TarFile.extractall = _extractall
installWmic()
installGetOptLong(getOptLongVer)

print ("")
print ("===================================")
print ("Nagios WMI Client Install Complete!")
print ("===================================")

文章末尾固定信息

 
alex
  • 本文由 alex 发表于 2017年8月16日 09:06:08
  • 转载请务必保留本文链接:https://www.qnjslm.com/ITHelp/206.html
    • zero
      zero 0

      不行

    匿名

    发表评论

    匿名网友
    :?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
    确定