本文整理匯總了Python中pyzabbix.ZabbixAPI方法的典型用法代碼示例。如果您正苦於以下問題:Python pyzabbix.ZabbixAPI方法的具體用法?Python pyzabbix.ZabbixAPI怎麽用?Python pyzabbix.ZabbixAPI使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pyzabbix
的用法示例。
在下文中一共展示了pyzabbix.ZabbixAPI方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: set_zabbix
# 需要導入模塊: import pyzabbix [as 別名]
# 或者: from pyzabbix import ZabbixAPI [as 別名]
def set_zabbix(self):
zabbix_host_text = self.zabbix_host.text()
zabbix_user_text = self.zabbix_user.text()
zabbix_pass_text = self.zabbix_pass.text()
try:
zapi = ZabbixAPI(str(zabbix_host_text))
zapi.login(str(zabbix_user_text), str(zabbix_pass_text))
self.connect_test.setStyleSheet("color: rgb(16, 172, 132)")
self.connect_test.setText("OK")
self.set_conf('Zabbix', 'zabbix_host', zabbix_host_text)
self.set_conf('Zabbix', 'zabbix_user', zabbix_user_text)
self.set_conf('Zabbix', 'zabbix_pass', zabbix_pass_text)
except:
self.connect_test.setStyleSheet("color: rgb(238, 82, 83)")
self.connect_test.setText("Invalid Credentials")
示例2: __init__
# 需要導入模塊: import pyzabbix [as 別名]
# 或者: from pyzabbix import ZabbixAPI [as 別名]
def __init__(self, base_url, login, password, verify_tls=True, timeout=None, **options):
self.options = options
self.key_patterns = {prepare_regex(metric['key']): metric
for metric in options.get('metrics', [])}
self.zapi = pyzabbix.ZabbixAPI(base_url, timeout=timeout)
if not verify_tls:
import requests.packages.urllib3 as urllib3
urllib3.disable_warnings()
self.zapi.session.verify = verify_tls
def measure_api_request(r, *args, **kwargs):
api_requests_total.inc()
api_bytes_total.inc(len(r.content))
api_seconds_total.inc(r.elapsed.total_seconds())
self.zapi.session.hooks = {'response': measure_api_request}
self.zapi.login(login, password)
self.host_mapping = {row['hostid']: row['name']
for row in self.zapi.host.get(output=['hostid', 'name'])}
示例3: __init__
# 需要導入模塊: import pyzabbix [as 別名]
# 或者: from pyzabbix import ZabbixAPI [as 別名]
def __init__(self, server, user, password, verify=True):
"""
Init zabbix class for further needs
:param user: string
:param password: string
:return: pyzabbix object
"""
self.server = server
self.user = user
self.password = password
# Enable HTTP auth
s = requests.Session()
s.auth = (user, password)
self.zapi = ZabbixAPI(server, s)
self.zapi.session.verify = verify
self.zapi.login(user, password)
self.version = self.get_version()
示例4: __init__
# 需要導入模塊: import pyzabbix [as 別名]
# 或者: from pyzabbix import ZabbixAPI [as 別名]
def __init__(self, url, login, password):
self.url = url
self.login = login
self.password = password
self.zbx_api = ZabbixAPI(url=url, use_authenticate=False, user=login, password=password)
log.debug('Object ZabbixAgent created')
log.debug('API ver. %s', self.api_ver())
示例5: __init__
# 需要導入模塊: import pyzabbix [as 別名]
# 或者: from pyzabbix import ZabbixAPI [as 別名]
def __init__(self):
self.hosts_dump = list()
self.hosts_dict = dict()
self.projects = list()
self.zapi = ZabbixAPI(os.getenv('ISOLATE_ZABBIX_URL'))
self.zapi.login(os.getenv('ISOLATE_ZABBIX_USER'), os.getenv('ISOLATE_ZABBIX_PASS'))
示例6: get
# 需要導入模塊: import pyzabbix [as 別名]
# 或者: from pyzabbix import ZabbixAPI [as 別名]
def get(cls, graph):
zabbix_client = ZabbixAPI(CONFIG.probes.zabbix.url)
return cls(
graph=graph,
upstream_proxy=upstream.UpstreamProxy(zabbix_client),
extractor=extractor.AlertExtractor.get(),
synchronizer=utils.NodeSynchronizer(graph),
resync_period=CONFIG.probes.zabbix.resync_period)
示例7: info_zabbix
# 需要導入模塊: import pyzabbix [as 別名]
# 或者: from pyzabbix import ZabbixAPI [as 別名]
def info_zabbix(self, bot, update):
if str(update.message.chat_id) == self.user_id_telegram and self.infozabbix.isChecked():
try:
self.zapi = ZabbixAPI(str(self.z_host))
self.zapi.timeout = 4.0
self.zapi.login(str(self.z_username), str(self.z_password))
update.message.reply_text("Zabbix is running.")
except:
update.message.reply_text("Zabbix is not running.")
else:
update.message.reply_text("I can't give this information for you!")
示例8: login
# 需要導入模塊: import pyzabbix [as 別名]
# 或者: from pyzabbix import ZabbixAPI [as 別名]
def login(self):
zapi = ZabbixAPI(self.ZABBIX_URL)
zapi.login(self.ZABBIX_USER, self.ZABBIX_PASSWORD)
return zapi
示例9: __init__
# 需要導入模塊: import pyzabbix [as 別名]
# 或者: from pyzabbix import ZabbixAPI [as 別名]
def __init__(self):
self.zapi = ZabbixAPI(zabbix_url)
self.zapi.session.auth = (zabbix_user, zabbix_pw)
self.zapi.session.verify = False
self.zapi.timeout = 5
self.zapi.login(zabbix_user, zabbix_pw)
self.val = 0.0
示例10: __init__
# 需要導入模塊: import pyzabbix [as 別名]
# 或者: from pyzabbix import ZabbixAPI [as 別名]
def __init__(self, server, user, password):
self.api = ZabbixAPI(server)
self.user = user
self.password = password
示例11: connect
# 需要導入模塊: import pyzabbix [as 別名]
# 或者: from pyzabbix import ZabbixAPI [as 別名]
def connect(self):
"""
Establishes a connection to the Zabbix server
Raises:
SystemExit
"""
if self.auth == "webform":
self.conn = ZabbixAPI(self.server)
elif self.auth == "http":
self.conn = ZabbixAPI(self.server, use_authenticate=False)
self.conn.session.auth = (self.username, self.password)
else:
raise SystemExit('api auth method not implemented: %s' % self.conn.auth)
if self.nocheckcertificate:
self.conn.session.verify = False
try:
self.conn.login(self.username, self.password)
except ZabbixAPIException as e:
raise SystemExit('Cannot login to Zabbix server: %s' % e)
self.logger.info("Connected to Zabbix API Version %s" % self.conn.api_version())
示例12: start_bot
# 需要導入模塊: import pyzabbix [as 別名]
# 或者: from pyzabbix import ZabbixAPI [as 別名]
def start_bot(self):
self.token, self.user_id_telegram, self.z_username, self.z_password, self.z_host = self.get_conf()
self.zapi = ZabbixAPI(str(self.z_host))
self.zapi.timeout = 4.0
try:
self.zapi.login(str(self.z_username), str(self.z_password))
except:
QtGui.QMessageBox.information(self, "Message", "Zabbix is not running! You need to fill in the connection details!")
return
self.updater = Updater(self.token)
dp = self.updater.dispatcher
dp.add_handler(CommandHandler("help", self.help))
dp.add_handler(CommandHandler("hosts", self.info_hosts))
dp.add_handler(CommandHandler("graphs", self.info_graphs, pass_args=True))
dp.add_handler(CommandHandler("status", self.info_zabbix))
dp.add_handler(CommandHandler("events", self.info_events))
dp.add_handler(CommandHandler("webs", self.info_webs))
dp.add_handler(CommandHandler("users", self.info_users))
dp.add_handler(MessageHandler(Filters.text, self.echo))
if self.infonotifications.isChecked():
try:
self.delete_script()
except:
pass
try:
self.create_script()
except:
QtGui.QMessageBox.information(self, "Message", "Check connection details!")
return
else:
QtGui.QMessageBox.information(self, "Message", "You need to mark 'Realtime notification'!")
return
self.updater.start_polling()
self.status.setStyleSheet("color: rgb(16, 172, 132)")
self.status.setText("Running")
self.infohosts.setEnabled(False)
self.infographs.setEnabled(False)
self.infozabbix.setEnabled(False)
self.infoevents.setEnabled(False)
self.infowebs.setEnabled(False)
self.infousers.setEnabled(False)
self.infonotifications.setEnabled(False)
self.start_button.setEnabled(False)
self.stop_button.setEnabled(True)