Skip to content

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

@halsbox

Description

@halsbox

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

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions