Jump to content
Sign in to follow this  
DavidLago

Reports from OpenFiles within a (file)server,(also monitoring the most used extensions)

Recommended Posts

DavidLago

Hello, fellows.

I recently gave fingerbirth to a script that reports out the current files, and users opening those files currently. Also provides a filter for strings/extensions.

Suggestions and improvements are welcome.

#cs  ---------------------------Script Start-------------------------------------
| Author:         DavidLago (Hellfrost)
| Script Function: Reports out a logfile containing openfiles within a (file)server, configured under an ini file
#ce  ----------------------------------------------------------------------------
;---------------------------------------------------------------INCLUDES--------------------------------------------------------------------------------
#include <Process.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <array.au3>
#include <Date.au3>
;------------------------------------------------------------EXPORT-FOLDER--------------------------------------------------------------------------------
If Not FileExists(@ScriptDir & "\Export") Then
DirCreate(@ScriptDir & "\Export")
EndIf
;------------------------------------------------------------ WHILE LOOP --------------------------------------------------------------------------------
Global $iNow = _NowCalc()
Global $TimeOut = False
While $TimeOut = False
;---------------------------------------------------------VARIABLES-----------------------------------------------------------------------------------
Global $Date = @MON & "-" & @MDAY & "-" & @YEAR
Global $Hour = @HOUR & "'" & @MIN & "''"
Global $FullDate = $Date & "_" & $Hour
Global $ReportDir = @ScriptDir & "\Export\"
;----------------------------------------------------------INI_READ-----------------------------------------------------------------------------------
Global $MailFrom = IniRead("Config.ini", "Mail", "MailFrom", "Script_OpenFiles@AutoITScripting.net")
Global $Mailto = IniRead("Config.ini", "Mail", "Mailto", "")
Global $MailSubj = IniRead("Config.ini", "Mail", "MailSubj", "")
Global $MailBody = IniRead("Config.ini", "Mail", "MailBody", "")
Global $TimeFreq = IniRead("Config.ini", "Time", "Frequency", "60")
Global $TimeDur = IniRead("Config.ini", "Time", "Duration", "24")
Global $ReportOut = $FullDate & "_" & IniRead("Config.ini", "ReportOut", "ReportOut", "Report")
Global $FilterExt = IniRead("Config.ini", "FilterExt", "FilterExt", "N")
Global $FileExt = '"' & IniRead("Config.ini", "FileExt", "FileExt", "exe") & '"'
Global $FormatOut = IniRead("Config.ini", "FormatOut", "FormatOut", "Table")
;-------------------------------------------------------MATH VARIABLES----------------------------------------------------------------------------------
Global $CommandCombo, $CommandFinal, $iDiff, $FreqDurMath
$iTimeFreq = $TimeFreq * 60000 ; Turn to miliseconds
$iTimeDur = $TimeDur ; Turn to minutes
$FreqDurMath = ($TimeDur * 60) / $TimeFreq
;-------------------------------------------------------ERROR-TREATMENT---------------------------------------------------------------------------------
If $iTimeFreq < 900000 Then
MsgBox(4112, "Error", 'The parameter "FREQUENCY" at the config.ini file is set to a number below 15. 15 minutes is the minumum threshold', 5)
$MailBody = 'The Script "' & @ScriptName & '" is reporting the following error: The parameter "FREQUENCY" at the config.ini file is set to a number below 15. ' & @CRLF & '15 minutes is the minumum threshold'
SendMail($MailBody)
Exit
EndIf
If $FreqDurMath < 1 Then
$MailBody = 'The Script "' & @ScriptName & '" The parameters "FREQUENCY" and "DURATION" at the config.ini file is set to a number which prevents it to loop more than once. Do you want to continue?'
SendMail($MailBody)
If MsgBox(4116, "Error", 'The parameters "FREQUENCY" and "DURATION" at the config.ini file is set to a number which prevents it to loop more than once. Do you want to continue?', 10) = 7 Then Exit
EndIf
;----------------------------------------------------------COMMAND BREED I-------------------------------------------------------------------------------
Global $QueryCommand = "/query " & "/FO " & $FormatOut & " /V " & "/nh "
Global $FindCommand = "| find /I " & $FileExt
Global $ExportCommand = " > " & '"' & $ReportDir & $ReportOut & ".log" & '"'
If $FilterExt = "Y" Then
$CommandCombo = $QueryCommand & $FindCommand & $ExportCommand
Else
$CommandCombo = $QueryCommand & $ExportCommand
EndIf
$CommandFinal = "openfiles " & $CommandCombo
;-------------------------------------------------------------OPTIONS-----------------------------------------------------------------------------------
If $FilterExt = "Y" Then
If $FileExt <> "" Then
TrayTip("Message from the " & @ScriptName & " Script: ", 'The command "' & $CommandFinal & '" is running in this server. Options enabled are the following:' & @CRLF & @CRLF & "Filter: " & '"' & $FilterExt & '"' & @CRLF & "Ext/String: " & $FileExt & @CRLF, 1, 1)
Else
TrayTip("Message from the " & @ScriptName & " Script: ", 'The command "' & $CommandFinal & '" is running in this server.', 1, 1)
EndIf
EndIf
;--------MAIN COMMAND-----------------------------------##################
_RunDOS($CommandFinal)
;--------MAIN COMMAND-----------------------------------##################
$iDiff = _DateDiff('h', $iNow, _NowCalc())
Sleep($iTimeFreq) ; <-Frequency
If $iDiff > $iTimeDur Then ; <-- Is time through?
$TimeOut = True
$MailBody = 'The script "' & @ScriptName & '", which was running at the server "' & @ComputerName & '", generated the requested logs successfully. Please, contact your Domain administrator to claim them'
SendMail($MailBody)
EndIf
WEnd ;==> While from line 18
 
;------------------------Function to send e-mail--------------------------------------------------------------------------------------------------------------
Func SendMail($MailBody)
$objEmail = ObjCreate("CDO.Message")
$objEmail.From = $MailFrom
$objEmail.To = $Mailto
$objEmail.Subject = $MailSubj
$objEmail.Textbody = $MailBody
$objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
$objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"mail.domain.net" ;                          <----------------------------------------- Insert your mailserver here
$objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
$objEmail.Configuration.Fields.Update
$objEmail.Send
EndFunc   ;==>SendMail

Contents of the config.ini file:

#--------------------------------------------------------------------#
#                           Config. ini                                          #
#--------------------------------------------------------------------#
#--------------------------------------------------------------------#
#   OPENFILES REPORT:             
#   Reports out a logfile containing openfiles within a server
#--------------------------------------------------------------------#
 
[Time]
 
# What frequency? (Minutes [minimum: 15 min) / How long? (Hours [Minimum: 1H)
Frequency = 15
Duration = 1
 
 
 
[FilterExt]
 
# GREP Extension/String? ( Y, N)
FilterExt = Y
 
 
 
[FileExt]
 
# What's the extension or string combo to be matched? (.exe; .doc; .csv; Solidworks; Report, etc. (default: line commented by #)
FileExt = doc
 
 
 
[ReportOut]
 
# LogFile Sufix
ReportOut = Report
 
 
 
[FormatOut]
 
# LogFile Format: CSV or Table. (default: table)
FormatOut = CSV
 
 
 
[Mail]
 
MailFrom = Script_OpenFiles@AutoITScripts.com
Mailto = hellfrost@hellfrost.info
MailSubj = OpenFiles Alert Example
MailBody = This message is an alert.

It might be useful for a Domain admin someday.


Just a server analyst that has never been into programming that much. So, small fish here :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Similar Content

    • Spartan117
      By Spartan117
      Hi everyone,
      I wonder if there is a cloud service that can offer a physical server so that AutoIT can turn as it is in a physical machine.
      Thank you
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      I'm working on a little project of mines, and I was trying to use WMI Object.
      The question which I don't find an answer is: 
      Once I do the query with WMI Object, something like "SELECT * FROM Win32_LogonSession", instead of specify the field of the collection returned, ( i.e. $colItems.Caption ), can I loop though each property and each value of the property, writing so one row of code only?
      Hope my question was clear enough.
      Thanks in advance.

      Best Regards.
    • nassausky
      By nassausky
      Hey all,
      Has anyone created any queries for youtube? I was thinking it might be something like this but can't quite figure it out:
      $oIE = _IECreateEmbedded() _IENavigate($oIE,"https://www.youtube.com") Local $oForms = _IETagNameGetCollection($oIE, "form") Local $sTxt = "" For $oForm In $oForms If $oForm.id = "masthead-search" Then $oInputs = _IETagNameGetCollection($oIE, "input") For $oInput In $oInputs If $oInput.id = "masthead-search-term" Then _IEFormElementSetValue($oInput, "cards") _IEFormSubmit($oForm) EndIf Next EndIf Next  
    • comtech80
      By comtech80
      Folks,
      I have an issue I've been trying to solve for a while, I'm trying to add static routes in DHCP via a 121 route rule in Windows 2012 R2 is a brutal manual process and wanted to automate this via AutoIT.
       
      When I use the "ControlGetText" everything displays properly in the MSG box but when I try and use "ControlSetText" or "ControlSend" the values won't display in the input box but the action comes back as successful?
      Anyone able to help me with this? I'm thinking this might be an active window issue but i'm not sure.
      Here is a part of my code.
       
      $hWnd = WinWait("[TITLE:Add a Static Route]","", 10)
      WinActivate($hWnd)
      $Status = ControlSend($hWnd, "", "[CLASS:Edit; INSTANCE:4]", "192"); Does not add 192 to the text box.
      Local $sTextEdit1 = ControlGetText($hWnd, "", "[CLASS:Edit; INSTANCE:1]")
      ConsoleWrite ( "ControlSend Status: " &  $Status & @CRLF); Returns a Value of 1
      ConsoleWrite ( "ControlGetText Value Edit1: " &  $sTextEdit1 & @CRLF);
       
      Please see attachment for more info.

    • ur
      By ur
      I have a button control as below screen.

      This one I am able to suppress using below code in all the OS.
      But on server 2008, sometimes the button highlighted in the image is not getting clicked and some times it is working.
      I have cross checked the IDs when it is not working, but it is working only.
       
      $win1 = "erwin Mart Configuration" $MartConfigWindow = _WinWaitActivate1($win1,"Database Details") ControlSetText($MartConfigWindow, "", "WindowsForms10.EDIT.app.0.378734a6", $dbserver) ControlSetText($MartConfigWindow, "", "WindowsForms10.EDIT.app.0.378734a4", $dbname) ControlSetText($MartConfigWindow, "", "WindowsForms10.EDIT.app.0.378734a9", $dbuser) ControlSetText($MartConfigWindow, "", "WindowsForms10.EDIT.app.0.378734a8", $dbpassword) ;Button clicl logic $iControlClickStatus = ControlClick($MartConfigWindow, "", "[CLASS:WindowsForms10.BUTTON.app.0.378734a; INSTANCE:2]") ;If above button click fails, trying with mouse click on the control if ControlFocus($MartConfigWindow, "", "WindowsForms10.BUTTON.app.0.378734a2")=1 then ;sometimes above button fails in win server 2008,so this loop Send("{ENTER") EndIf  
      Any suggestion on how to resolve this.?
×