fix: nodename quotation issue

* update nodename method to not use regex anymore
* update readme with 2 new columns for the exit code table

We used quite the broad regex to parse the nodename from the status
string. But we relied on a single quote to mark the starting point.
It seems some distributions don't have this starting quote,
therefore breaking the api.
This commit is contained in:
nico 2020-11-24 23:37:00 +01:00
parent c19557a320
commit ac0ea074d5
Signed by: mightyBroccoli
GPG Key ID: EA7C31AAB1BDC1A2
2 changed files with 18 additions and 8 deletions

View File

@ -113,9 +113,9 @@ Another possible solution would be to edit the `ExecStart` parameter to include
Lookup table for all custom error codes. Lookup table for all custom error codes.
The potential reasons are sorted by probability of being the root cause. The potential reasons are sorted by probability of being the root cause.
| code | potential reason | | code | raised by | cause by | potential reason |
| :---: | :---| | :---: | :---| : --- | :--- |
| 17 | login credential mismatch, potential api permission problem | | 17 | calls | api call returned empty | login credential mismatch, potential api permission problem |
### pre-commit framework ### pre-commit framework
This project utilizes the [pre-commit](https://pre-commit.com/) framework to automate various small hick-ups that tend This project utilizes the [pre-commit](https://pre-commit.com/) framework to automate various small hick-ups that tend

View File

@ -14,16 +14,26 @@ class EjabberdApiCalls(EjabberdApi):
@property @property
def nodename(self): def nodename(self):
if self._login is not None: if self._login is not None:
node_str = re.compile("The node '(.*)'")
status = self.cmd("status", {}) status = self.cmd("status", {})
# "The node ejabberd@localhost is started with status: startedejabberd 20.07 is running in that node"
# matches
try: try:
tmp = node_str.findall(status)[0] tmp = status.split()[2]
# raise SystemExit code 17 if no status message is received
except TypeError: except AttributeError:
# emtpy response or None obj
raise SystemExit(17) raise SystemExit(17)
except IndexError:
# status string differs from what we expect
log.warning("status string is different then expected")
tmp = "ejabberd@status-string-split-error"
pass
# strip double quotations
if tmp.startswith("'"):
tmp = tmp.strip("'")
log.debug(f"fetched node string: {tmp}") log.debug(f"fetched node string: {tmp}")
return tmp return tmp