BUG: agent_hp_msa login failed - encoding of username and password missing

Hello.

agent_hp_msa connection test fails.

I am running RAW version on CentOS 7.9 fully updated.
I am running RAW version 2.0.0p1.
The same problem was present in version 2.0.0.

Manual agent execution outputs the same error I see in connection test web GUI.
Command output follows.

OMD[checkmk]:~/share/check_mk/agents/special$ ./agent_hp_msa -v --debug -u manage -p <hidden_password> msa2050a
Traceback (most recent call last):
  File "./agent_hp_msa", line 12, in <module>
    sys.exit(main())
  File "/omd/sites/checkmk/lib/python3/cmk/special_agents/agent_hp_msa.py", line 179, in main
    connection.login(args.username, args.password)
  File "/omd/sites/checkmk/lib/python3/cmk/special_agents/agent_hp_msa.py", line 137, in login
    session_key = self._get_session_key(hashlib.sha256, username, password)
  File "/omd/sites/checkmk/lib/python3/cmk/special_agents/agent_hp_msa.py", line 147, in _get_session_key
    login_hash.update("%s_%s" % (username, password))
TypeError: Unicode-objects must be encoded before hashing

MSA 2050 password complexity check requires the following:

it must contain at least one uppercase character, one lowercase character, one numeric character, and one non-alphanumeric character.

So my password contains a full-stop (.).

Am I missing something?
Best regards.

Hello,

we’re getting this error with 2.0.0p1 too. The agent hp_msa had an error in version 2.0.0 before but it used to be a different message (“TypeError” like in werk #12377).

Best Regards

I think the problem is that the string for username and password are not correctly encoded.
This is some of the Python 3 changes. I had last week one system with also a own special agent and the same problem - how to encode the username and passwords.

In the special agent in the function “_get_session_key” the username and password must get the addition .encode('utf8') before it can passed to the hashlib function.

1 Like

Hello Andreas,

I didn’t succeed simply adding .encode(‘utf-8’) to username and password variables.
I’m not a python programmer so I may have coded it wrong.
Can you help please?

I was able to fix the check.

Snippet of “_get_session_key”

    def _get_session_key(self, hash_class, username, password):
        login_hash = hash_class()
        accessstring = "%s_%s" % (username, password)
        login_hash.update(accessstring.encode())

Snippet of “main”

    # Output sections
    for section, lines in sections.items():
        print("<<<hp_msa_%s>>>" % section)
        print("\n".join(str(x) for x in lines))
1 Like

Hello Sebastian,

your patch is working fine.
I eventually managed to get my MSA 2050 under monitor.
Now you should have your patch merged in the nex release of Checkmk.

— agent_hp_msa.py.orig 2021-03-16 21:52:38.000000000 +0100
+++ agent_hp_msa.py 2021-03-18 09:12:47.615184542 +0100
@@ -144,7 +144,8 @@

 def _get_session_key(self, hash_class, username, password):
     login_hash = hash_class()
  •    login_hash.update("%s_%s" % (username, password))
    
  •    accessstring = "%s_%s" % (username, password)
    
  •    login_hash.update(accessstring.encode())
       login_url = "login/%s" % login_hash.hexdigest()
       response = self.get(login_url)
       xml_tree = ET.fromstring(response.text)
    

@@ -190,6 +191,6 @@
# Output sections
for section, lines in sections.items():
print(“<<<hp_msa_%s>>>” % section)

  •    print("\n".join(x.encode("utf-8") for x in lines))
    
  •    print("\n".join(str(x) for x in lines))
    

    return 0

Best regards.
Alberto

Sorry for wrong patch formatting.
hyphen (-) and sum (+) have been translated into bullets.

@_rb

I had this on a few systems as well, with this solution solving the error, could you take a look if you want to include this patch in the p2 ?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact @fayepal if you think this should be re-opened.