Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- set up user agent #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions zabbix/zabbix_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def __init__(self, server='http://localhost/zabbix', user=httpuser, passwd=httpp
self.server = server
self.url = server + '/api_jsonrpc.php'
self.proto = self.server.split("://")[0]
self.user_agent
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syntax error

#self.proto=proto
self.httpuser = user
self.httppasswd = passwd
Expand All @@ -154,6 +155,12 @@ def set_log_level(self, level):
self.debug(logging.INFO, "Set logging level to %d" % level)
self.logger.setLevel(level)

def set_user_agent(self, user_agent):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to move user_agent parameter to init and remove this methods, because user agent must not changed in session

self.user_agent = user_agent

def get_user_agent(self):
return self.user_agent

def recent_query(self):
"""
return recent query
Expand Down Expand Up @@ -218,8 +225,7 @@ def test_login(self):

def do_request(self, json_obj):
headers = {'Content-Type': 'application/json-rpc',
'User-Agent': 'python/zabbix_api'}

'User-Agent': 'python/zabbix_api/' + self.user_agent}
if self.httpuser:
self.debug(logging.INFO, "HTTP Auth enabled")
auth = 'Basic ' + string.strip(base64.encodestring(self.httpuser + ':' + self.httppasswd))
Expand Down