Python Forum
SaltStack: MySQL returner save less data into Database table columns
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SaltStack: MySQL returner save less data into Database table columns
#1
I'm trying to modify the existing SaltStack MySQL returner to only save a handful of data instead of the default columns
(| fun | jid | return | id | success | full_ret) to something like

(| fun | jid | return | id | success)

The file I'm working on is this one:
https://github.com/saltstack/salt/blob/m...s/mysql.py

I installed this python module python3-mysqldb so Salt can communicate with MySQL v8.0.25

The part that I modified (line 313)


  try:
        with _get_serv(ret, commit=True) as cur:
            sql = """INSERT INTO `salt_returns`
                     (`fun`, `jid`, `id`, `success`)
                     VALUES (%s, %s, %s, %s)"""
But I'm getting this error when running something like
salt '*' test.ping --return mysql

Error:
2021-07-01 11:46:05,693 [salt.minion :2055][ERROR ][16794] The return failed for job 20210701174605511891: not all arguments converted during string formatting Traceback (most recent call last): File "/usr/lib/python3/dist-packages/MySQLdb/cursors.py", line 238, in execute query = query % args TypeError: not all arguments converted during string formatting During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/salt/minion.py", line 2044, in _thread_return minion_instance.returners[returner_str](ret) File "/usr/lib/python3/dist-packages/salt/loader.py", line 1235, in __call__ return self.loader.run(run_func, *args, **kwargs) File "/usr/lib/python3/dist-packages/salt/loader.py", line 2268, in run return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs) File "/usr/lib/python3/dist-packages/salt/loader.py", line 2283, in _run_as return _func_or_method(*args, **kwargs) File "/usr/lib/python3/dist-packages/salt/returners/mysql.py", line 327, in returner salt.utils.json.dumps(ret), File "/usr/lib/python3/dist-packages/MySQLdb/cursors.py", line 240, in execute self.errorhandler(self, ProgrammingError, str(m)) File "/usr/lib/python3/dist-packages/MySQLdb/connections.py", line 52, in defaulterrorhandler raise errorclass(errorvalue) _mysql_exceptions.ProgrammingError: not all arguments converted during string formatting
I'm guessing it comes down to how each column in the table was defined, but I'm not sure where to make further modifications to write data in only those columns.
Reply
#2
First we are not fond of providing code as a link. We are a bit scared of where a link brings us.
Second: when you delete "full_ret" from the query, you should also remove it from the tuple. So delete line 327.
    salt.utils.json.dumps(ret),
Reply
#3
(Jul-02-2021, 11:32 AM)ibreeden Wrote: First we are not fond of providing code as a link. We are a bit scared of where a link brings us.
Second: when you delete "full_ret" from the query, you should also remove it from the tuple. So delete line 327.
    salt.utils.json.dumps(ret),

Thanks!

That was what I needed, also had to modify the column to be able to accept NULL values.

Appreciated
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I need help parsing through data and creating a database using beautiful soup username369 1 73 5 hours ago
Last Post: Larz60+
  mySQL Database error not resolving. cybertooth 2 194 Aug-30-2021, 05:45 PM
Last Post: ibreeden
  Python Pandas: How do I average ONLY the data >1000 from several columns? JaneTan 0 314 Jul-17-2021, 01:34 PM
Last Post: JaneTan
  [Solved] Using readlines to read data file and sum columns Laplace12 4 497 Jun-16-2021, 12:46 PM
Last Post: Laplace12
  Reading data from mysql. stsxbel 2 555 May-23-2021, 06:56 PM
Last Post: stsxbel
  Need help on extract dynamic table data Dr_Strange 0 718 Apr-30-2021, 07:03 AM
Last Post: Dr_Strange
  Load the data from multiple source files to one table amy83 2 648 Apr-27-2021, 12:33 AM
Last Post: Pedroski55
  How to save json data in a dataframe shantanu97 1 556 Apr-15-2021, 02:44 PM
Last Post: klllmmm
  Pandas: how to split one row of data to multiple rows and columns in Python GerardMoussendo 4 1,705 Feb-22-2021, 06:51 PM
Last Post: eddywinch82
  Yahoo_fin, Pandas: how to convert data table structure in csv file detlefschmitt 14 2,344 Feb-15-2021, 12:58 PM
Last Post: detlefschmitt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020