The can be done with system stored procedure xp_readerrorlog
Step 1
Create a new stored procedure using the following code:
CREATE PROCEDURE spLoginAttempts
AS
BEGIN
DECLARE @temp Table (LogDate datetime, ProcessInfo nvarchar(20), Text nvarchar(100))
INSERT INTO @temp
EXECUTE xp_readerrorlog 0, 1, 'Login failed', 'administrator'
SELECT COUNT (*) FROM @temp
WHERE Logdate > DATEADD(HOUR, -24, GETDATE())
END
This wil return the the number of failed login attempts for the administrator over the last 24 hours.
Step 2
For this to work, you need to enable "Login auditing" on your sql-server. To enable "Login auditing" follow the steps below:
- Start SQL Server management Studio.
- Connect to your SQL server.
- Right click your server in the 'object explorer' pane and select 'Properties'.
- Select the 'Security' page and determine when login auditing should take place.
Step 3
Add a new Custom XML sensor
We can now add a Microsoft-SQL sensor that runs the Stored Procedure (SQL expression = exec spLoginAttempts) and check for the return value.
Add comment