本文整理汇总了Python中Nagstamon.Servers.Generic.GenericServer.init_HTTP方法的典型用法代码示例。如果您正苦于以下问题:Python GenericServer.init_HTTP方法的具体用法?Python GenericServer.init_HTTP怎么用?Python GenericServer.init_HTTP使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nagstamon.Servers.Generic.GenericServer
的用法示例。
在下文中一共展示了GenericServer.init_HTTP方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_HTTP
# 需要导入模块: from Nagstamon.Servers.Generic import GenericServer [as 别名]
# 或者: from Nagstamon.Servers.Generic.GenericServer import init_HTTP [as 别名]
def init_HTTP(self):
"""
initializing of session object
"""
GenericServer.init_HTTP(self)
if not 'Referer' in self.session.headers:
self.session.headers['Referer'] = self.monitor_cgi_url + '/icingaweb2/monitoring'
# normally cookie out will be used
if not self.no_cookie_auth:
if len(self.session.cookies) == 0:
# get login page, thus automatically a cookie
login = self.FetchURL('{0}/authentication/login'.format(self.monitor_url))
if login.error == '' and login.status_code == 200:
form = login.result.find('form')
form_inputs = {}
for form_input in ('redirect', 'formUID', 'CSRFToken', 'btn_submit'):
if not form.find('input', {'name': form_input}) is None:
form_inputs[form_input] = form.find('input', {'name': form_input})['value']
else:
form_inputs[form_input] = ''
form_inputs['username'] = self.username
form_inputs['password'] = self.password
# fire up login button with all needed data
self.FetchURL('{0}/authentication/login'.format(self.monitor_url), cgi_data=form_inputs)
示例2: init_HTTP
# 需要导入模块: from Nagstamon.Servers.Generic import GenericServer [as 别名]
# 或者: from Nagstamon.Servers.Generic.GenericServer import init_HTTP [as 别名]
def init_HTTP(self):
"""
things to do if HTTP is not initialized
"""
GenericServer.init_HTTP(self)
# prepare for JSON
self.session.headers.update({'Accept': 'application/json',
'Content-Type': 'application/json'})
# get cookie to access Opsview web interface to access Opsviews Nagios part
if len(self.session.cookies) == 0:
if conf.debug_mode:
self.Debug(server=self.get_name(), debug="Fetching Login token")
logindata = json.dumps({'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
resp = literal_eval(self.FetchURL(self.monitor_url + "/rest/login",
giveback='raw',
cgi_data=logindata).result)
if conf.debug_mode:
self.Debug(server=self.get_name(), debug="Login Token: " + resp.get('token') )
self.session.headers.update({'X-Opsview-Username': self.get_username(),
'X-Opsview-Token':resp.get('token')})
except:
self.Error(sys.exc_info())
示例3: init_HTTP
# 需要导入模块: from Nagstamon.Servers.Generic import GenericServer [as 别名]
# 或者: from Nagstamon.Servers.Generic.GenericServer import init_HTTP [as 别名]
def init_HTTP(self):
"""
Initializing of session object
"""
GenericServer.init_HTTP(self)
self.session.auth = NoAuth()
if len(self.session.cookies) == 0:
form_inputs = dict()
if self.username.startswith('ldap:'):
form_inputs['module'] = 'ldap'
form_inputs['_username'] = self.username[5:]
else:
form_inputs['module'] = 'sv'
form_inputs['_username'] = self.username
form_inputs['urm:login:client'] = ''
form_inputs['_password'] = self.password
# call login page to get temporary cookie
self.FetchURL('{0}/security/login'.format(self.monitor_url))
# submit login form to retrieve authentication cookie
self.FetchURL(
'{0}/security/login_check'.format(self.monitor_url),
cgi_data=form_inputs,
multipart=True
)
示例4: init_HTTP
# 需要导入模块: from Nagstamon.Servers.Generic import GenericServer [as 别名]
# 或者: from Nagstamon.Servers.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.session.headers:
# to execute actions since Icinga 1.11 a Referer Header is necessary
self.session.headers["Referer"] = self.monitor_cgi_url + "/cmd.cgi"
示例5: init_HTTP
# 需要导入模块: from Nagstamon.Servers.Generic import GenericServer [as 别名]
# 或者: from Nagstamon.Servers.Generic.GenericServer import init_HTTP [as 别名]
def init_HTTP(self):
# general initialization
GenericServer.init_HTTP(self)
# Fix eventually missing tailing '/' in url
if self.monitor_url[-1] != '/':
self.monitor_url += '/'
# Prepare all urls needed by nagstamon if not yet done
if len(self.urls) == len(self.statemap):
self.urls = {
'api_services': self.monitor_url + 'view.py?view_name={0}&output_format=python&lang=&limit=hard'.\
format(self.check_mk_view_services),
'human_services': self.monitor_url + 'index.py?%s' % \
urllib.parse.urlencode({'start_url': 'view.py?view_name={0}'.\
format(self.check_mk_view_services)}),
'human_service': self.monitor_url + 'index.py?%s' %
urllib.parse.urlencode({'start_url': 'view.py?view_name=service'}),
'api_hosts': self.monitor_url + 'view.py?view_name={0}&output_format=python&lang=&limit=hard'.\
format(self.check_mk_view_hosts),
'human_hosts': self.monitor_url + 'index.py?%s' %
urllib.parse.urlencode({'start_url': 'view.py?view_name={0}'.\
format(self.check_mk_view_services)}),
'human_host': self.monitor_url + 'index.py?%s' %
urllib.parse.urlencode({'start_url': 'view.py?view_name=hoststatus'}),
# URLs do not need pythonic output because since werk #0766 API does not work with transid=-1 anymore
# thus access to normal webinterface is used
'api_host_act': self.monitor_url + 'view.py?_transid=-1&_do_actions=yes&_do_confirm=Yes!&view_name=hoststatus&filled_in=actions&lang=',
'api_service_act': self.monitor_url + 'view.py?_transid=-1&_do_actions=yes&_do_confirm=Yes!&view_name=service&filled_in=actions&lang=',
'api_svcprob_act': self.monitor_url + 'view.py?_transid=-1&_do_actions=yes&_do_confirm=Yes!&view_name=svcproblems&filled_in=actions&lang=',
'human_events': self.monitor_url + 'index.py?%s' %
urllib.parse.urlencode({'start_url': 'view.py?view_name=events'}),
'transid': self.monitor_url + 'view.py?actions=yes&filled_in=actions&host=$HOST$&service=$SERVICE$&view_name=service'
}
self.statemap = {
'UNREACH': 'UNREACHABLE',
'CRIT': 'CRITICAL',
'WARN': 'WARNING',
'UNKN': 'UNKNOWN',
'PEND': 'PENDING',
}
if self.CookieAuth:
# get cookie to access Check_MK web interface
if 'cookies' in dir(self.session):
if len(self.session.cookies) == 0:
# if no cookie yet login
self._get_cookie_login()
elif self.session == None:
# if no cookie yet login
self._get_cookie_login()
示例6: init_HTTP
# 需要导入模块: from Nagstamon.Servers.Generic import GenericServer [as 别名]
# 或者: from Nagstamon.Servers.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.Servers.Generic import GenericServer [as 别名]
# 或者: from Nagstamon.Servers.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)
# only if cookies are needed
if self.CookieAuth:
# get cookie to access Thruk web interface
# Thruk first send a test cookie, later an auth cookie
if len(self.session.cookies) < 2:
# get cookie from login page via url retrieving as with other urls
try:
# login and get cookie
self.login()
except:
self.Error(sys.exc_info())
示例8: init_HTTP
# 需要导入模块: from Nagstamon.Servers.Generic import GenericServer [as 别名]
# 或者: from Nagstamon.Servers.Generic.GenericServer import init_HTTP [as 别名]
def init_HTTP(self):
"""
things to do if HTTP is not initialized
"""
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()}
"""
self.session.headers.update({"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.session.cookies) == 0:
# put all necessary data into url string
logindata = urllib.parse.urlencode({'login_username': self.get_username(),
'login_password': self.get_password(),
'back': '',
'app': 'OPSVIEW',
'login': 'Sign in',
'noscript': '1'})
# the following is necessary for Opsview servers
# get cookie from login page via url retrieving as with other urls
try:
# login and get cookie
self.FetchURL(self.monitor_url + "/login", cgi_data=logindata, giveback='raw')
except:
import traceback
traceback.print_exc(file=sys.stdout)
self.Error(sys.exc_info())
示例9: init_HTTP
# 需要导入模块: from Nagstamon.Servers.Generic import GenericServer [as 别名]
# 或者: from Nagstamon.Servers.Generic.GenericServer import init_HTTP [as 别名]
def init_HTTP(self):
"""
initialize HTTP connection
"""
if self.session == None:
GenericServer.init_HTTP(self)
if self.centreon_version == None:
result_versioncheck = self.FetchURL(self.monitor_cgi_url + '/index.php', giveback='raw')
raw_versioncheck, error_versioncheck = result_versioncheck.result, result_versioncheck.error
if error_versioncheck == '':
if re.search('2\.2\.[0-9]', raw_versioncheck):
self.centreon_version = 2.2
if conf.debug_mode == True:
self.Debug(server=self.get_name(), debug='Centreon version detected : 2.2')
# URLs for browser shortlinks/buttons on popup window
self.BROWSER_URLS= { 'monitor': '$MONITOR$/main.php?p=1',\
'hosts': '$MONITOR$/main.php?p=20103&o=hpb',\
'services': '$MONITOR$/main.php?p=20202&o=svcpb',\
'history': '$MONITOR$/main.php?p=203'}
elif re.search('2\.[3-6]\.[0-5]', raw_versioncheck):
self.centreon_version = 2.3456
if conf.debug_mode == True:
self.Debug(server=self.get_name(), debug='Centreon version detected : 2.6.5 <=> 2.3')
# URLs for browser shortlinks/buttons on popup window
self.BROWSER_URLS= { 'monitor': '$MONITOR$/main.php?p=1',\
'hosts': '$MONITOR$/main.php?p=20103&o=hpb',\
'services': '$MONITOR$/main.php?p=20202&o=svcpb',\
'history': '$MONITOR$/main.php?p=203'}
elif re.search('2\.6\.[6-9]', raw_versioncheck):
self.centreon_version = 2.66
if conf.debug_mode == True:
self.Debug(server=self.get_name(), debug='Centreon version detected : 2.6.6')
# URLs for browser shortlinks/buttons on popup window
self.BROWSER_URLS= { 'monitor': '$MONITOR$/main.php?p=1',\
'hosts': '$MONITOR$/main.php?p=20103&o=hpb',\
'services': '$MONITOR$/main.php?p=20202&o=svcpb',\
'history': '$MONITOR$/main.php?p=203'}
elif re.search('2\.7\.[0-9]', raw_versioncheck):
# Centreon 2.7 only support C. Broker
self.centreon_version = 2.7
if conf.debug_mode == True:
self.Debug(server=self.get_name(), debug='Centreon version detected : 2.7')
# URLs for browser shortlinks/buttons on popup window
self.BROWSER_URLS= { 'monitor': '$MONITOR$/main.php?',\
'hosts': '$MONITOR$/main.php?p=20202&o=hpb',\
'services': '$MONITOR$/main.php?p=20201&o=svcpb',\
'history': '$MONITOR$/main.php?p=203'}
else:
# unsupported version or unable do determine
self.centreon_version = 2.7
if conf.debug_mode == True:
self.Debug(server=self.get_name(), debug='Centreon version unknown : supposed to be >= 2.7')
# URLs for browser shortlinks/buttons on popup window
self.BROWSER_URLS= { 'monitor': '$MONITOR$/main.php?',\
'hosts': '$MONITOR$/main.php?p=20202&o=hpb',\
'services': '$MONITOR$/main.php?p=20201&o=svcpb',\
'history': '$MONITOR$/main.php?p=203'}
else:
if conf.debug_mode == True:
self.Debug(server=self.get_name(), debug='Error getting the home page : ' + error_versioncheck)
del result_versioncheck, raw_versioncheck, error_versioncheck
示例10: init_HTTP
# 需要导入模块: from Nagstamon.Servers.Generic import GenericServer [as 别名]
# 或者: from Nagstamon.Servers.Generic.GenericServer import init_HTTP [as 别名]
def init_HTTP(self):
"""
initialize HTTP connection
"""
if self.session == None:
GenericServer.init_HTTP(self)