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

Login to zabbix does not work if not default locale is set for zabbix login screen #92

Open
halsbox opened this issue Oct 23, 2017 · 1 comment
Assignees
Labels

Comments

@halsbox
Copy link

halsbox commented Oct 23, 2017

Hi
If Zabbix is setup with not the default locale for login screen (e.g. russian, as in my case), than POST request to login fails because of Zabbix expecting translated value for "enter" field (e.g. "Войти" instead of "Sign in"), while "Sign in" is hardcoded in zbxtg.py. Simple solution is to adjust data_api variable in login function of ZabbixAPI class to suite your locale. More generic solution is to request the Zabbix JSON API key and then use it to construct the cookie for regular request to chart3.php, here is the patch:

--- zbxtg.py.orig	2017-10-23 21:23:29.844699802 +0300
+++ zbxtg.py	2017-10-23 21:19:38.638553246 +0300
@@ -275,16 +275,26 @@
         if not self.verify:
             requests.packages.urllib3.disable_warnings()
 
-        data_api = {"name": self.username, "password": self.password, "enter": "Sign in"}
-        answer = requests.post(self.server + "/", data=data_api, proxies=self.proxies, verify=self.verify,
+        data_api = {
+            "jsonrpc": "2.0",
+            "method": "user.login",
+            "params": {
+                "user": self.username,
+                "password": self.password
+            },
+            "id": 1,
+            "auth": None
+        }
+        answer = requests.post(self.server + "/api_jsonrpc.php", json=data_api, proxies=self.proxies, verify=self.verify,
                                auth=requests.auth.HTTPBasicAuth(self.basic_auth_user, self.basic_auth_pass))
-        cookie = answer.cookies
         if len(answer.history) > 1 and answer.history[0].status_code == 302:
             print_message("probably the server in your config file has not full URL (for example "
                           "'{0}' instead of '{1}')".format(self.server, self.server + "/zabbix"))
-        if not cookie:
+        if (answer.status_code != 200) or ('result' not in answer.json()):
             print_message("authorization has failed, url: {0}".format(self.server + "/"))
             cookie = None
+        else:
+            cookie = {"zbx_sessionid": answer.json()['result']}
 
         self.cookie = cookie
@ableev ableev added the bug label Dec 20, 2017
@ableev ableev self-assigned this Dec 20, 2017
@ableev
Copy link
Owner

ableev commented Dec 20, 2017

@halsbox thanks for the report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants