Requests for Automation

Agent Removal by Inactivity to free up license

I am looking to create a procedure that will check the Kaseya DB for inactive agents and remove by inactivity. This is for clients that may have PC's that are not checking in frequently or have been offline for an extended period of Time. But only removed from Kaseya DB so that when the system comes back online, it checks back in and license is then re-allocated. Thoughts / Thanks!

This request was archived: Feature request

Discussion
Gravatar for Pieter Jorritsma
Pieter Jorritsma 9 months ago

Forget to add something when create you can execute it with EXEC [NAME].[spDeleteAgentByInactivity]  

With that you can create a way to schedule it even though agent procedure ;)

Gravatar for Pieter Jorritsma
Pieter Jorritsma 9 months ago

Forget to add something when create you can execute it with EXEC [NAME].[spDeleteAgentByInactivity]  

With that you can create a way to schedule it even though agent procedure ;)

Gravatar for Pieter Jorritsma
Pieter Jorritsma 9 months ago

Hello Paul,

Would like to be something like this:

USE ksubscribers;  

GO  

CREATE PROCEDURE [NAME].[spDeleteAgentByInactivity]   

AS

BEGIN   

DECLARE @counterId varchar(50)

DECLARE curCounters CURSOR

FOR

SELECT dbo.machNameTab.agentGuid

FROM dbo.agentState JOIN dbo.machNameTab ON dbo.agentState.agentGuid = dbo.machNameTab.agentGuid

WHERE case when dbo.agentState.online = 0 then datediff(day, dbo.agentState.offlineTime, getdate()) else 0 end > 180

OPEN curCounters

FETCH next FROM curCounters INTO @counterId;

WHILE @@FETCH_STATUS = 0

BEGIN

DELETE FROM machNameTab WHERE agentGuid = @counterId

DELETE FROM users WHERE agentGuid = @counterId

DELETE FROM agentState WHERE agentGuid = @counterId

DELETE FROM acctRename WHERE oldAgentGuid = @counterId

FETCH next FROM curCounters INTO @counterId;

END

CLOSE curCounters

DEALLOCATE curCounters

GO

Note: Use at on risk. 

Gravatar for Paul E Szelagiewicz
Paul E Szelagiewicz over 1 year ago

Found this, but cannot import SQL to Kaseya

DECLARE @counterId varchar(50)

use ksubscribers

DECLARE curCounters CURSOR

FOR

SELECT dbo.machNameTab.agentGuid

FROM dbo.agentState JOIN dbo.machNameTab ON dbo.agentState.agentGuid = dbo.machNameTab.agentGuid

WHERE case when dbo.agentState.online = 0 then datediff(day, dbo.agentState.offlineTime, getdate()) else 0 end > 180

OPEN curCounters

FETCH next FROM curCounters INTO @counterId;

WHILE @@FETCH_STATUS = 0

BEGIN

print @counterId

DELETE FROM machNameTab WHERE agentGuid = @counterId

DELETE FROM users WHERE agentGuid = @counterId

DELETE FROM agentState WHERE agentGuid = @counterId

DELETE FROM acctRename WHERE oldAgentGuid = @counterId

FETCH next FROM curCounters INTO @counterId;

END

CLOSE curCounters

DEALLOCATE curCounters

Details

  • Request Archived
  • 6 Votes
  • 4 Comments
  • Open for over 1 year
  • Created by Paul E Szelagiewicz