neilmunday / Salt-Minion-Inventory

Salt Minion Inventory provides a web based interface to your SaltStack minions to view their state.
GNU General Public License v3.0
36 stars 4 forks source link

After executing 'salt * inventory.audit' ,No data is written to the database #29

Closed hanzechu01 closed 5 years ago

hanzechu01 commented 5 years ago

[WARNING ] /usr/lib/python2.7/site-packages/salt/payload.py:149: DeprecationWarning: encoding is deprecated, Use raw=False instead. ret = msgpack.loads(msg, use_list=True, ext_hook=ext_type_decoder, encoding=encoding)

salt-syndic-node1: salt-syndic-node1 properties have not changed

neilmunday commented 5 years ago

Hi,

Which operating system(s) are you using on your Salt master and minions?

Which version(s) of SaltStack are you using on your Salt master and minions?

If no records are being written to the database then then it sounds like the issue is on the server side where the inventory.py runner is executed - this script is invoked when presence and audit events are triggered by minions and writes records to the database.

1) Can you confirm that the server that is your Salt master can access your MySQL server?

2) Can you confirm that required Python modules are installed on your Salt master? You can check by loading the python interpreter at the command line and then by entering the following commands:

import MySQLdb
import pytz

If either of these import commands fail, then please install the appropriate Python packages for your operating system and try again.

3) Load two shells on your Salt master and run the following command in the first shell:

tail -f /var/log/salt/master

In the second shell run:

salt '*' inventory.audit force=True

Take a note of any errors that are reported in the first shell in the Salt master log. You can then exit the tail command using Ctrl + C.

4) If there were no useful errors from the previous step, in the first shell run the following command to view Salt's event queue:

salt-run state.event pretty=True

Now in the second shell run:

salt '*' inventory.audit force=True

There should be a few events appearing in the first shell. Look for any errors in the output.

hanzechu01 commented 5 years ago

Hello 1.My Salt master: Salt Version: Salt: 2019.2.0 2.Currently only Centos ,Can you ask if this supports Windows 10? 3.My Salt MAster can connect to the database 4.When I run tail -f /var/log/salt/master and salt '*' inventory.audit force=True

I found it: 2019-06-20 08:07:29,267 [py.warnings :149 ][WARNING ][102773] /usr/lib/python2.7/site-packages/salt/payload.py:149: DeprecationWarning: encoding is deprecated, Use raw=False instead. ret = msgpack.loads(msg, use_list=True, ext_hook=ext_type_decoder, encoding=encoding) 2019-06-20 08:07:30,591 [salt.utils.reactor:401 ][ERROR ][5000] Reactor 'inventory_audit' failed to execute runner 'inventory.audit': function not available 2019-06-20 08:07:36,160 [salt.utils.reactor:401 ][ERROR ][5000] Reactor 'inventory_present' failed to execute runner 'inventory.present': function not available

Please help solve this problem

Thank you

neilmunday commented 5 years ago

The inventory module will not work on Windows 10 Salt Minions as there is Linux specific code in the module. I believe that the runner would work on a Windows 10 Salt Master but this has not been tested.

It looks like your Salt Master cannot find the inventory.py runner.

Can you confirm that you have the following in your /etc/salt/master config file:

extension_modules: /var/lib/salt

If not, please add the above and restart your Salt master.

Also please confirm that /var/lib/salt/runners exists and contains the following files:

If not, please copy these files from the runners directory from Salt Minion Inventory download.

Then restart your Salt Master.

Also, do you have selinux enabled?

hanzechu01 commented 5 years ago

Hello Now I can confirm extension_modules in /etc/salt/master: /var/lib/saltwill already exist and /var/lib/salt/runners It exists Can be seen from the picture selinunx is shut down image image image this run tail -f /var/log/salt/master and salt salt-syndic-node1 inventory.audit force=True after that I found this 2019-06-20 15:43:10,324 [py.warnings :149 ][WARNING ][7569] /usr/lib/python2.7/site-packages/salt/payload.py:149: DeprecationWarning: encoding is deprecated, Use raw=False instead. ret = msgpack.loads(msg, use_list=True, ext_hook=ext_type_decoder, encoding=encoding)

neilmunday commented 5 years ago

Can you confirm if you are using the SaltStack python 2 or 3 version? From the warning message you have shared I am assuming version 2. I don't see this error on my server which is running the python 2 version of Salt Stack 2019. This could be coming from something else in your SaltStack set-up.

In one of my previous replies I asked if you could run:

salt-run state.event pretty=True

in one shell and then in a second shell run:

salt '*' inventory.audit force=True

Can you share the output from the SaltStack event queue? It should show the inventory.audit function being executed on the minion(s), the result returned to the queue and then the result of the reactor running. Hopefully there will be some useful info here.

neilmunday commented 5 years ago

Looks like the warning message you are seeing is due to a known issue: https://github.com/saltstack/salt/pull/52487

It would appear that this fix has been included in Salt Stack 2019.2.1 - there are no RPMs for this version at this time. I don't think that this warning explains why the Salt Minion Inventory isn't working though.

hanzechu01 commented 5 years ago

hello

Please check the version

image

image

On the picture is my execution Salt-run state.event pretty=True and salt '*' results of inventory.audit force=True Sorry, because the queue is too long, there is no way to show you all image I saw a lot of data that needs to be written to the database from the queue, but still did not write to the database.

Do you need to set anything else in the salt master?

neilmunday commented 5 years ago

Thanks for the screen shots.

It looks like the Python interpreter cannot find the ConfigParser module which is normally installed as part of the python-libs RPM under CentOS.

Does /usr/lib64/python2.7/ConfigParser.py exist on your Salt Master? Is the python-libs RPM installed?

hanzechu01 commented 5 years ago

Hello friend ! image I have this ConfigParser.py exist

neilmunday commented 5 years ago

What happens if you try importing the ConfigParser in the Python 2?

E.g. load the python interpreter:

python

Then type:

import ConfigParser

You should see this:

$ python
Python 2.7.5 (default, Apr  9 2019, 14:30:50)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ConfigParser
>>>
hanzechu01 commented 5 years ago

Yes, my results are the same as yours. image Is this okay?

neilmunday commented 5 years ago

Thanks for the info. Yes, that is the correct output, however I wasn't expecting it to work under your set-up as for some reason the module is not found when running under SaltStack.

I've just made some minor modifications to the runner to make it work with the Python 3 version of SaltStack also. Have you tried this version at some point? I only ask as one of your earlier screen shots shows in /var/lib/salt/runners a sub directory called pycache which is only created when using Python 3.

Please can you try downloading https://raw.githubusercontent.com/neilmunday/Salt-Minion-Inventory/master/runners/inventory.py and saving it to /var/lib/salt/runners/inventory.py. Then restart your Salt Master: systemctl restart salt-master.

Now try the tests above again please.

hanzechu01 commented 5 years ago

image

I downloaded the new Inventory.py and restarted the master's service. After executing salt -l debug 'node1' inventory.audit force = True, it looks like this.

neilmunday commented 5 years ago

Looks like you have put a space either side of the equals sign. Please run like so:

salt 'node1' inventory.audit force=True

hanzechu01 commented 5 years ago

Hello friend! Thank you very much for your support and help. The function has been implemented.

neilmunday commented 5 years ago

Excellent - are you happy for this issue to be closed?