Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. declare @numberDaysBack int = 1
  2. declare @errorLogCount int
  3. declare @lastLogDate datetime
  4. declare @errorLogInfo table(
  5. LogDate datetime,
  6. ProcessInfo nvarchar(50),
  7. [Text] nvarchar(max)
  8. )
  9. declare @enumErrorLogs table(
  10. Archive# int,
  11. [Date] datetime,
  12. LogFileSizeMB int
  13. )
  14. insert into @enumErrorLogs
  15. exec sp_enumerrorlogs
  16. select @errorLogCount = MIN(Archive#), @lastLogDate = MAX([Date])
  17. from @enumErrorLogs
  18. while @errorLogCount is not null
  19. begin
  20. insert into @errorLogInfo
  21. exec sp_readerrorlog
  22. @errorLogCount
  23. select @errorLogCount = MIN(Archive#), @lastLogDate = MAX([Date])
  24. from @enumErrorLogs
  25. where Archive# > @errorLogCount
  26. and @lastLogDate > getdate() - @numberDaysBack
  27. end
  28.  
  29. -- List all last week failed logins count of attempts and the Login failure message
  30. select COUNT(TEXT) as NumberOfAttempts, TEXT as Details, MIN(LogDate) as MinLogDate, MAX(LogDate) as MaxLogDate
  31. from @errorLogInfo
  32. where ProcessInfo = 'Logon'
  33. and TEXT like '%fail%'
  34. and LogDate > getdate() - @numberDaysBack
  35. group by TEXT
  36. order by NumberOfAttempts desc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement