Skip to content

Commit

Permalink
mysql-table-indexes: Improve output
Browse files Browse the repository at this point in the history
  • Loading branch information
markuslf committed Dec 7, 2023
1 parent 4bf9e7a commit a9463aa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 3 additions & 1 deletion check-plugins/mysql-table-indexes/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ Output:

.. code-block:: text
Tables without indexes: employees.current_dept_emp, employees.dept_emp_latest_date [WARNING]
Tables without indexes [WARNING]:
* employees.current_dept_emp
* employees.dept_emp_latest_date
States
Expand Down
14 changes: 6 additions & 8 deletions check-plugins/mysql-table-indexes/mysql-table-indexes
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def main():
# init some vars
msg = ''
state = STATE_OK
tables = []

# TABLE_SCHEMA and TABLE_NAME must be uppercase due to MySQL 8+
sql = '''
Expand Down Expand Up @@ -132,20 +133,17 @@ def main():
'''.format(schema['TABLE_SCHEMA'], table['TABLE_NAME'])
user_indexes = lib.base.coe(lib.db_mysql.select(conn, sql))
if len(user_indexes) == 0:
msg += '{}.{}, '.format(
schema['TABLE_SCHEMA'],
table['TABLE_NAME'],
)
tables.append('{}.{}'.format(schema['TABLE_SCHEMA'], table['TABLE_NAME']))

lib.db_mysql.close(conn)

if not msg:
if not tables:
msg = 'Everyhing is ok.'
else:
state = STATE_WARN
msg = 'Tables without indexes: {}{}'.format(
msg[:-2],
lib.base.state2str(state, prefix=' ')
msg = 'Tables without indexes {}:\n* {}'.format(
lib.base.state2str(state),
'\n* '.join(tables),
)

# over and out
Expand Down

0 comments on commit a9463aa

Please sign in to comment.