本文整理汇总了Python中Nagstamon.Server.Generic.GenericServer.init_HTTP方法的典型用法代码示例。如果您正苦于以下问题:Python GenericServer.init_HTTP方法的具体用法?Python GenericServer.init_HTTP怎么用?Python GenericServer.init_HTTP使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nagstamon.Server.Generic.GenericServer
的用法示例。
在下文中一共展示了GenericServer.init_HTTP方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_HTTP
# 需要导入模块: from Nagstamon.Server.Generic import GenericServer [as 别名]
# 或者: from Nagstamon.Server.Generic.GenericServer import init_HTTP [as 别名]
def init_HTTP(self):
"""
partly not constantly working Basic Authorization requires extra Autorization headers,
different between various server types
"""
GenericServer.init_HTTP(self)
#if self.HTTPheaders == {}:
# for giveback in ["raw", "obj"]:
# self.HTTPheaders[giveback] = {"Authorization": "Basic " + base64.b64encode(self.get_username() + ":" + self.get_password())}
# only if cookies are needed
if self.CookieAuth:
# get cookie to access Check_MK web interface
if len(self.Cookie) < 2:
# put all necessary data into url string
logindata = urllib.urlencode({"login":self.get_username(),\
"password":self.get_password(),\
"submit":"Login"})
# get cookie from login page via url retrieving as with other urls
try:
# login and get cookie
# empty referer seems to be ignored so add it manually
urlcontent = self.urlopener.open(self.monitor_cgi_url + "/login.cgi?", logindata + "&referer=")
urlcontent.close()
except:
self.Error(sys.exc_info())
示例2: init_HTTP
# 需要导入模块: from Nagstamon.Server.Generic import GenericServer [as 别名]
# 或者: from Nagstamon.Server.Generic.GenericServer import init_HTTP [as 别名]
def init_HTTP(self):
if self.HTTPheaders == {}:
GenericServer.init_HTTP(self)
# special Opsview treatment, transmit username and passwort for XML requests
# http://docs.opsview.org/doku.php?id=opsview3.4:api
# this is only necessary when accessing the API and expecting a XML answer
self.HTTPheaders["xml"] = {
"Content-Type": "text/xml",
"X-Username": self.get_username(),
"X-Password": self.get_password(),
}
# get cookie to access Opsview web interface to access Opsviews Nagios part
if len(self.Cookie) == 0:
# put all necessary data into url string
logindata = urllib.urlencode(
{
"login_username": self.get_username(),
"login_password": self.get_password(),
"back": "",
"app": "",
"login": "Log In",
}
)
# the following is necessary for Opsview servers
# get cookie from login page via url retrieving as with other urls
try:
# login and get cookie
urlcontent = self.urlopener.open(self.monitor_url + "/login", logindata)
urlcontent.close()
except:
self.Error(sys.exc_info())
示例3: init_HTTP
# 需要导入模块: from Nagstamon.Server.Generic import GenericServer [as 别名]
# 或者: from Nagstamon.Server.Generic.GenericServer import init_HTTP [as 别名]
def init_HTTP(self):
if self.HTTPheaders == {}:
GenericServer.init_HTTP(self)
# get cookie to access Opsview web interface to access Opsviews Nagios part
if len(self.Cookie) == 0:
if str(self.conf.debug_mode) == "True":
self.Debug(server=self.get_name(), debug="Fetching Login token")
# put all necessary data into url string
logindata = urllib.urlencode({"username":self.get_username(),\
"password":self.get_password(),})
# the following is necessary for Opsview servers
# get cookie from login page via url retrieving as with other urls
try:
# login and get cookie
urlcontent = self.urlopener.open(self.monitor_url + "/rest/login", logindata)
resp = literal_eval(urlcontent.read().decode("utf8", errors="ignore"))
if str(self.conf.debug_mode) == "True":
self.Debug(server=self.get_name(), debug="Login Token: " + resp.get('token') )
self.HTTPheaders["raw"] = {"Accept":"application/json","Content-Type":"application/json", "X-Opsview-Username":self.get_username(), "X-Opsview-Token":resp.get('token')}
urlcontent.close()
except:
self.Error(sys.exc_info())
示例4: init_HTTP
# 需要导入模块: from Nagstamon.Server.Generic import GenericServer [as 别名]
# 或者: from Nagstamon.Server.Generic.GenericServer import init_HTTP [as 别名]
def init_HTTP(self):
"""
initialize HTTP connection
"""
if self.HTTPheaders == {}:
GenericServer.init_HTTP(self)
# Centreon xml giveback method just should exist
self.HTTPheaders["xml"] = {}
示例5: init_HTTP
# 需要导入模块: from Nagstamon.Server.Generic import GenericServer [as 别名]
# 或者: from Nagstamon.Server.Generic.GenericServer import init_HTTP [as 别名]
def init_HTTP(self):
"""
Icinga 1.11 needs extra Referer header for actions
"""
GenericServer.init_HTTP(self)
if not "Referer" in self.HTTPheaders:
# to execute actions since Icinga 1.11 a Referer Header is necessary
for giveback in ["raw", "obj"]:
self.HTTPheaders[giveback]["Referer"] = self.monitor_cgi_url + "/cmd.cgi"
示例6: init_HTTP
# 需要导入模块: from Nagstamon.Server.Generic import GenericServer [as 别名]
# 或者: from Nagstamon.Server.Generic.GenericServer import init_HTTP [as 别名]
def init_HTTP(self):
self.statemap = {
'UNREACH': 'UNREACHABLE',
'CRIT': 'CRITICAL',
'WARN': 'WARNING',
'UNKN': 'UNKNOWN',
'PEND': 'PENDING',
'0': 'OK',
'1': 'UNKNOWN',
'2': 'WARNING',
'5': 'CRITICAL',
'3': 'WARNING',
'4': 'CRITICAL'}
GenericServer.init_HTTP(self)
示例7: init_HTTP
# 需要导入模块: from Nagstamon.Server.Generic import GenericServer [as 别名]
# 或者: from Nagstamon.Server.Generic.GenericServer import init_HTTP [as 别名]
def init_HTTP(self):
# Fix eventually missing tailing "/" in url
self.statemap = {
"UNREACH": "UNREACHABLE",
"CRIT": "CRITICAL",
"WARN": "WARNING",
"UNKN": "UNKNOWN",
"PEND": "PENDING",
"0": "OK",
"1": "UNKNOWN",
"2": "WARNING",
"5": "CRITICAL",
"3": "WARNING",
"4": "CRITICAL",
}
GenericServer.init_HTTP(self)
示例8: init_HTTP
# 需要导入模块: from Nagstamon.Server.Generic import GenericServer [as 别名]
# 或者: from Nagstamon.Server.Generic.GenericServer import init_HTTP [as 别名]
def init_HTTP(self):
# add default auth for monitor.old
GenericServer.init_HTTP(self)
# self.Cookie is a CookieJar which is a list of cookies - if 0 then emtpy
if len(self.Cookie) == 0:
try:
# Ninja Settings
# get a Ninja cookie via own method
self.urlopener.add_handler(urllib2.HTTPDefaultErrorHandler())
self.urlopener.open(self.login_url, urllib.urlencode({'username': self.get_username(), 'password': self.get_password(), 'csrf_token': self.csrf()}))
if str(self.conf.debug_mode) == "True":
self.Debug(server=self.get_name(), debug="Cookie:" + str(self.Cookie))
except:
self.Error(sys.exc_info())
示例9: init_HTTP
# 需要导入模块: from Nagstamon.Server.Generic import GenericServer [as 别名]
# 或者: from Nagstamon.Server.Generic.GenericServer import init_HTTP [as 别名]
def init_HTTP(self):
# add default auth for monitor.old
GenericServer.init_HTTP(self)
# self.Cookie is a CookieJar which is a list of cookies - if 0 then emtpy
if len(self.Cookie) == 0:
try:
# Ninja Settings
self.commit_url = self.nagios_url + '/index.php/command/commit'
self.login_url = self.nagios_url + '/index.php/default/do_login'
self.time_url = self.nagios_url + '/index.php/extinfo/show_process_info'
# get a Ninja cookie via own method
self.urlopener.open(self.login_url, urllib.urlencode({'username': self.get_username(), 'password': self.get_password()}))
if str(self.conf.debug_mode) == "True":
self.Debug(server=self.get_name(), debug="Cookie:" + str(self.Cookie))
except:
self.Error(sys.exc_info())