Hello John
I am sorry to hear that you were running these tests in a productive environment, and did not expect the deletion of disconnected agents. Maybe I misunderstood the initial message but the initial query was how to generate such alerts, how to make such rules trigger. Sorry if I wasn't clear, but the same documentation I passed you indicates that the monitord module deletes the agent if that functionality is configured.
docuI will now try to be as clear as possible in answering each query.
1) Customer: So should I remove the <if_fts> part from rule 501 ?
No, becuse is the unique difference between rule 501 and 503, the idea is 501 (New ossec agent connected) fires first time that monitord reports "Agent started", following messages should trigger rule 503 (Agent started), ever talking about same agent that, rule
link, decoder
link
2) Customer: Please let me know where I can find the agent operational logs like the one shared above i-e Agent disconnected, started, stopped or removed... As I am unable to find the logs (Against which rule 501 -505 will match) , just to bring into your knowledge I can't find the operational i-e Agent disconnected, started, stopped or removed logs inside the ossec.log file at the monitored server (Where wazuh agent is installed), so please let me know where I can find such logs? are they logged on the wazuh server end ? if yes then where ?
I think you are talking about following event
{"timestamp":"2023-05-10T08:15:36.688-0300","rule":{"level":3,"description":"Ossec agent started.","id":"503","firedtimes":1,"mail":false,"groups":["ossec"],"pci_dss":["10.6.1","10.2.6"],"gpg13":["10.1"],"gdpr":["IV_35.7.d"],"hipaa":["164.312.b"],"nist_800_53":["AU.6","AU.14","AU.5"],"tsc":["CC7.2","CC7.3","CC6.8"]},"agent":{"id":"001","name":"DESKTOP","ip":"2803:9800:9882:1111:5E87:5DE6:1111:BBBB"},"manager":{"name":"VBox"},"id":"16837173.33015","full_log":"ossec: Agent started: 'DESKTOP-U8OHD3A->any'.","decoder":{"parent":"ossec","name":"ossec"},"data":{"extra_data":"DESKTOP->any"},"location":"wazuh-agent"}
That is an alert, I found it in
/var/ossec/logs/alert/alert.json in the manager side, that file is enabled by default and contains every alert in the system, is the result of procesing a log and match with a rule, it includes the name and id
"Ossec agent started.","id":"503
If you want see the logs in manager side, look for them in
/var/ossec/logs/ossec.log also in manager side. there are every Wazuh internal log, you can increse the verbosity of that log enabling it in
/var/ossec/etc/local_internal_options.conf file.
How it works, rules 501 to 505 were created to be used with monitord, monitord informs (into
/var/ossec/logs/ossec.log) when an agent has just connected, or it's disconnect from the manager, also it has te capability to delete old agents using
monitord.delete_old_agents option, the possible messages from remoted are internal messages, defined in the code:
/* OSSEC alert messages */
"ossec: Manager started."
"ossec: Agent started: '%s->%s'."
"ossec: Agent stopped: '%s->%s'."
"ossec: Agent disconnected: '%s'."
"ossec: Agent removed: '%s'."
for example from my alert shared above, the message that triggers my rule was the section in the full_log, "
ossec: Agent started: 'DESKTOP-U8OHD3A->any'" how my agent was already created it fires rule number 503 instead 501.
link to code messages.
3) Customer: If rule 501 and 503 are the same then what's the purpose to create two rules for same behavior ? like in both cases it will match "Agent started" which means it will trigger everytime an existing agent 's service is started for any reason.. that means these rules will not distinguish between the existing agent or when a new agent in installed...
Same answer as first question.
4) Customer: Please let me know where I can find the agent operational logs like the one shared above.
You can find them in
/var/ossec/logs/ossec.log.
Are difined in
link to code messages.
5) Customer: Could you please elaborate and explain in more detail about the monitord.delete_old_agents because when I enabled it with the value 5 and then proceed to uninstalled the agent on the server it trigger no rule for rule it 505 instead it removed all the disconnected agents from wazuh server agent dashboard (Alarming and create panic at our end) .. our objective here is just to trigger an alert when ever wazuh agent is uninstalled ore removed from the user or the monitored system end (Where agent is installed).
The
monitord.delete_old_agents option represents the number of minutes before deleting a disconnected agent from the manager list, agents are kept installed on each node, they are just removed from the manager list, if an agent tries to connect to the manager again, and the autoenrollment functionality is enabled, it will do so.
linkRegarding
our objective here is just to trigger an alert when ever wazuh agent is uninstalled ore removed from the user or the monitored system end (Where agent is installed).
I think it's not possible know if anget is unistalled or removed from the user, only if is appear as a disconnected in the system, agent send the
SHUTDOWN message or
stop, when it is stopped, but if it is then uninstalled, there is no agent to collect that information from the node log and send it to the manager.
Normal communication between agent an manager are, agent send a start message, then functional messages with collected events or keepalives, to know that is alive, and if agent has to stops send an stop message or shutdown (there you can see the agent as discconected in the dashboard), in case the machine shuts down without properly closing the agent, the shutdow message does not arrive, the dashboard will show it as connected for 10 minutes, after that time without receiving any message from that agent it will be switched to disconnected.
In conclusion, rules from 501 to 505 are triggered by monitord messages. If you think we should improve this feature, you could always open an issue with your feature request in
https://github.com/wazuh/wazuh and we will evaluate with the team how and when to implement it.
I hope this information is useful to you and your team, sorry again if I wasn't clear.
Regards.