Jump to content

steelsking

Active Members
  • Posts

    30
  • Joined

  • Last visited

Everything posted by steelsking

  1. Phew!!!! Thanks alot jchd!!! Appreciate it alot! It works fine now!
  2. hi Realm, thanks for your reply. but tats not the issue. i cant upload ini files in here, hence renamed it to txt files.
  3. Hi guys, #include <Date.au3> Global $YYMMDD = StringMid(@YEAR & @MON & @MDAY, 3) Global $inifile = @ScriptDir & "\settings.ini" Global $mfile = @ScriptDir & "\monitor" & "_" & $YYMMDD & ".ini" Dim $i $Count2 = IniRead($inifile, "Alert", "Count", "Count2NotFound") $var = IniReadSectionNames($mfile) If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.") Else For $i = 1 To $var[0] $Start3 = IniRead($mfile, $var[$i], "Start", "Start3NotFound") $End3 = IniRead($mfile, $var[$i], "End", "End3NotFound") $Count3 = IniRead($mfile, $var[$i], "Count", "Count3NotFound") $iDateCalc = _DateDiff('n', $Start3, $End3) If $Count3 > $Count2 Then MsgBox(0, "Alert", "Source : " & $var[$i] & @CRLF & "Duration : " & $iDateCalc & " mins" & @CRLF & "Count : " & $Count3) EndIf Next EndIf Exit When I run the above codes for the attached file, it only displays the last result. Why is it so? Can someone kindly guide me? Thank you! monitor_111121.txt settings.txt
  4. wow!!! so many ways to achieve this! thanks alot guys!
  5. hi guys, with the following log file, how do I extract just the Serial thingy? 598761: May 5 22:33:52: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/4, changed state to up 598762: May 5 22:34:12: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/4, changed state to down 598763: May 5 22:35:12: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/7, changed state to up 598764: May 5 22:35:32: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/7, changed state to down 598765: May 5 22:35:42: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/7, changed state to up 598766: May 5 22:36:12: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/7, changed state to down 598767: May 5 22:39:02: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/0, changed state to up 598768: May 5 22:39:32: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/0, changed state to down 598769: May 5 22:40:12: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/0, changed state to up 598770: May 5 22:40:42: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/0, changed state to down 598771: May 5 22:46:32: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/4, changed state to up 598772: May 5 22:46:52: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/4, changed state to down 598773: May 5 22:49:12: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/4, changed state to up 598774: May 5 22:49:42: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/4, changed state to down 598775: May 5 22:50:52: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/0, changed state to up 598776: May 5 22:50:52: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/5, changed state to up 598777: May 5 22:51:22: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/0, changed state to down 598778: May 5 22:51:22: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/5, changed state to down 598779: May 5 23:00:22: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/6, changed state to up 598780: May 5 23:00:42: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/0, changed state to up 598781: May 5 23:00:52: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/6, changed state to down 598782: May 5 23:01:12: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/0, changed state to down 598783: May 5 23:06:02: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/4, changed state to up 598784: May 5 23:06:32: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/4, changed state to down 598785: May 5 23:07:32: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/4, changed state to up 598786: May 5 23:08:02: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/4, changed state to down 598787: May 5 23:09:34: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/5, changed state to up 598788: May 5 23:10:02: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/5, changed state to down 598789: May 5 23:14:53: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/5, changed state to up 598790: May 5 23:15:23: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/1/5, changed state to down 598791: May 5 23:15:33: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/6, changed state to up 598792: May 5 23:16:03: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/6, changed state to down 598793: May 5 23:20:13: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/7, changed state to up 598794: May 5 23:20:43: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/7, changed state to down 598795: May 5 23:23:43: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/6, changed state to up 598796: May 5 23:24:13: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial10/0/6, changed state to down 598797: May 5 23:34:53: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/7, changed state to up 598798: May 5 23:35:23: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial12/0/7, changed state to down I just the "Serial12/0/7" meaning Serial till the "," kindly assist. Thanks.
  6. hi guys, appreciate if someone could help me out here. i am new to vb.net this script had been working in my company for a long time. but the guy who code it has already left. the problem now is it doesn't work in 64bits machines. how do i go about converting this to au3? i do not understand what most of the lines mean? can someone please guide me along here.....? thanks.
  7. hi melba23, thanks alot!!! it works!!! sorry for the delay, was testing it out. Thanks!
  8. Hi, I have the following log file. 2011-10-18 07:38:39 Local7.Notice 172.17.164.134 1671: Oct 18 07:45:40 SIN: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up 2011-10-18 07:38:40 Local7.Error 172.17.164.134 1672: Oct 18 07:45:40 SIN: %LINK-3-UPDOWN: Interface FastEthernet0/1, changed state to down 2011-10-18 07:38:41 Local7.Notice 172.17.164.134 1673: Oct 18 07:45:41 SIN: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down 2011-10-18 07:38:41 Local7.Error 172.17.164.134 1674: Oct 18 07:45:42 SIN: %LINK-3-UPDOWN: Interface FastEthernet0/1, changed state to up 2011-10-18 07:38:43 Local7.Notice 172.17.164.134 1675: Oct 18 07:45:44 SIN: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up 2011-10-18 07:38:47 Local7.Error 172.17.164.134 1676: Oct 18 07:45:48 SIN: %LINK-3-UPDOWN: Interface FastEthernet0/1, changed state to down 2011-10-18 07:38:48 Local7.Notice 172.17.164.134 1677: Oct 18 07:45:49 SIN: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down 2011-10-18 07:38:49 Local7.Error 172.17.164.134 1678: Oct 18 07:45:49 SIN: %LINK-3-UPDOWN: Interface FastEthernet0/1, changed state to up 2011-10-18 07:38:49 Local7.Notice 172.17.164.134 1679: Oct 18 07:45:50 SIN: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up What I need to do is to detect if any particular IP address is having an up and down status based on the logs files, within a stipulated time. meaning to detect if within a space of 5 mins, if there are X numbers of ups and down, to sent an alert. I have tried the following. Not sure if it is the tried easy logical method. I couldnt proceed further as I got stuck. Hope someone can guide me along. Thanks. #include <file.au3> #include <Array.au3> #include <Date.au3> Global $YYMMDD = StringMid(@YEAR & @MON & @MDAY, 3) Global $inifile = @ScriptDir & "\settings.ini" Global $Search = IniReadSection($inifile, "Search") Global $Temp = @ScriptDir & "\tempdb" & "_" & $YYMMDD & ".txt" Dim $aRecords, $aTemp If Not _FileReadToArray("error.log", $aRecords) Then MsgBox(4096, "Error", "Error reading log to Array error: " & @error) Exit EndIf If Not FileExists(@ScriptDir & "\tempDB" & "_" & $YYMMDD & ".txt") Then FileInstall("temp.txt", @ScriptDir & "\tempDB" & "_" & $YYMMDD & ".txt", 1) IniWrite($inifile, "config", "LastEOF", "0") ;Exit EndIf For $j = 1 To $Search[0][0] For $x = 1 To $aRecords[0] $aParts = StringSplit($aRecords[$x], @TAB) $result = StringInStr($aParts[4], $Search[$j][1]) If $result = 0 Then $DT = StringReplace($aParts[1], "-", "/") $Combine = $DT & @TAB & $aParts[3] If Not _FileReadToArray($Temp, $aTemp) Then MsgBox(4096, "Error", "Error reading tempDB to Array error: " & @error) Exit EndIf If (_ArraySearch($aTemp, $Combine) = -1) Then FileWriteLine($Temp, $Combine) Else For $i = 1 To $aTemp[0] Step 1 $aParts2 = StringSplit($aTemp[$i], @TAB) If IsArray($aParts2) And ($aParts2[2] = $aParts[3]) Then MsgBox(0, "", "Found.") FileWriteLine($Temp, $Combine) EndIf Next EndIf EndIf Next Next Exit ini file [Config] FileLocName="error.log" [search] 1=changed state to up 2=changed state to down [settings] Frequency=10 Threshold=5
  9. "172.17.174.1 13: Cisco Internetwork Operating System Software" to "172.17.174.1 Cisco Internetwork Operating System Software" pls take note that this number cd be single digit or more. thanks UEZ!
  10. thanks UEZ! work very well, but just one more little issue. $string = "172.17.153.7 2008 Jan 14 06:57:02 SIN +08:00 %CDP-4-NVLANMISMATCH:Native vlan mismatch detected on port 3/6" & @CRLF & _ "172.17.183.134 17: 07:45:48: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/13, changed state to down" & @CRLF & _ "172.17.174.134 4303: 2y14w: %LINK-3-UPDOWN: Interface FastEthernet0/7, changed state to down" & @CRLF & _ "172.17.174.1 13: Cisco Internetwork Operating System Software" $filter = StringRegExpReplace($string, "(\d+\.\d+\.\d+\.\d+ )(.*%)", "$1") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $filter = ' & @CRLF & $filter & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console MsgBox(0, "RegEx", $filter) Thanks!
  11. thanks for the help Malkey. but as I went thru the logs file, it failed to parse the following lines correctly. 172.17.183.134 17: 07:45:48: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/13, changed state to down 172.17.174.134 4303: 2y14w: %LINK-3-UPDOWN: Interface FastEthernet0/7, changed state to down to 172.17.183.134 LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/13, changed state to down 172.17.174.134 LINK-3-UPDOWN: Interface FastEthernet0/7, changed state to down please help me. thanks once again!
  12. hi guys, sorry, i hit into a problem. the following line is parsed correctly from this 172.17.112.6 2008 Jan 14 00:02:17 SIN +08:00 %DTP-5-TRUNKPORTON:Port 6/44 has become isl trunk to 172.17.112.6 DTP-5-TRUNKPORTON:Port 6/44 has become isl trunk but these lines do not. 172.17.175.129 55182: Jan 14 00:05:38: %LANCE-5-LATECOLL: Unit 0, late collision error to 172.17.175.129 LANCE-5-LATECOLL: Unit 0, late collision error kindly assist please. thank you very much!
  13. thank you guys for all the help and detailed explanation!!!
  14. Hi GeoSoft, thanks for the codes. however, is there any simpler way of doing this? will the codes work on other lines? thanks.
  15. hi everyone, i am very confused on using the StringReg Exp function. how do i strip thw following 172.17.153.7 2008 Jan 14 06:57:02 SIN +08:00 %CDP-4-NVLANMISMATCH:Native vlan mismatch detected on port 3/6 to this 172.17.153.7 CDP-4-NVLANMISMATCH:Native vlan mismatch detected on port 3/6 thank you!
  16. hi everyone, For $j = 1 To $Search[0][0] For $i = $LastEOF + 1 To $aRecords[0] Step 1 $aParts = StringSplit($aRecords[$i], @TAB) If IsArray($aParts) And (UBound($aParts) >= 5) And ($aParts[2] = $Search[$j][1]) Then If Not _FileReadToArray($Temp, $aTemp) Then MsgBox(4096, "Error", "Error reading templog to Array error: " & @error) Exit EndIf If (_ArraySearch($aTemp, $aParts[3] & @TAB & $aParts[4]) = -1) Then FileWriteLine($Temp, $aParts[3] & @TAB & $aParts[4]) ;Run(@ComSpec & " /c " & $Paging, "", @SW_HIDE) MsgBox(0, "", $aParts[3] & @TAB & $aParts[4]) EndIf EndIf Next Next i have 2 For loops. it is not working though. i guess u can't a for loop inside another for loop... can someone please help me out here? thanks.
  17. thanks! sorry last 2 questions. 1) 2008-01-14 00:00:29 Local7.Notice 172.17.112.6 2008 Jan 14 00:02:17 SIN +08:00 %DTP-5-TRUNKPORTON:Port 6/44 has become isl trunk for this eg line, i only want to know the values from 172.17..... I think it is the fourth array (array[3]) i guess. how do i modify this line to extract that values? $extract = StringRegExp($aParts[4], "%(?:[^:]+):(.*)", 1) 2) to enable multiple search criteria, if i have this ini file [search] 1=apple 2=orange 3=pear 4=mango $var = IniReadSection("myfile.ini", "search") For $i = 1 To $var[0][0] $criteria = $var[$i][1]) Next how do i incorporate this into the following search line? If IsArray($aParts) And (UBound($aParts) >= 5) And ($aParts[2] = $Search) Then Thanks once again!!!
  18. Hi Smartee, appreciate your kind assistance again. 1) The script is not exiting once it has been run. I want it to exit each time it is run and then continue from last EOF when re-run again. 2) Since the script is not exiting, I have a problem when a new day arrives. thanks!
  19. smartee, you rock!!! thank you so much, its working now!! appreciate your help all these while. and thanks for the detailed explanation too. it is helping me in comparing where i went wrong. cheers!
  20. what do I want to do exactly? based on the ini file search, i want the script to go thru the log file and check to see if the search is found. if found and if it is not repeated or found elsewhere, to run a command. and each time the script runs, it should start from where it last left off as the lines of the log file keep increasing. thank you!
  21. hi smartee! thanks for helping. however I have the following error msg when I run the script. Line 45 If ($aParts[2] = $Search) Then If (^ ERROR Error : Array variable has incorrect number of subscripts or subscript dimension range exceeded. Appreciate your help again. SyslogCatchAll.txt
  22. Hi, I came out with the following code. No errors are reported but it is not working right. It doesn't seem to do the search function. Can someone kindly help me out here....? Thanks. #NoTrayIcon #include <Array.au3> #include <File.au3> #include <Process.au3> Global $YYMMDD = StringMid(@YEAR & @MON & @MDAY, 3) Global $Temp = @ScriptDir & "\templog" & "_" & $YYMMDD & ".txt" Global $inifile = @ScriptDir & "\settings.ini" Global $Search = IniRead($inifile, "config", "Search", "") Global $Paging = IniRead($inifile, "config", "Paging", "") Global $LastEOF = IniRead($inifile, "config", "LastEOF", "") Global $FileLocationName = IniRead($inifile, "config", "FileLocName", "") Dim $aRecords If Not FileExists(@ScriptDir & "\settings.ini") Then FileInstall("set.ini", @ScriptDir & "\settings.ini", 1) MsgBox(0, "Missing configuration file restored", "Please update the default settings.ini before proceeding.") Run("notepad.exe " & @ScriptDir & "\settings.ini", "", @SW_MAXIMIZE) Exit EndIf $Date = IniRead($inifile, "config", "date", "date") If $Date <> $YYMMDD Then IniWrite($inifile, "config", "date", $YYMMDD) IniWrite($inifile, "config", "LastEOF", "0") EndIf If Not FileExists(@ScriptDir & "\templog" & "_" & $YYMMDD & ".txt") Then FileInstall("temp.txt", @ScriptDir & "\templog" & "_" & $YYMMDD & ".txt", 1) Exit EndIf While 1 If Not _FileReadToArray($FileLocationName, $aRecords) Then MsgBox(4096, "Error", "Error reading log to Array error: " & @error) Exit EndIf MsgBox(0, "Alert", "I am here now.") For $x = $LastEOF + 1 To $aRecords[0] If ($aRecords[2] = $Search) Then $extract = StringRegExp($aRecords[4], "%(?:[^:]+):(.*)", 1) If (_ArraySearch($aRecords, $extract[0]) = -1) Then FileWriteLine($Temp, $extract[0]) Run(@ComSpec & " /c " & $Paging, "", @SW_HIDE) EndIf EndIf Next $CountLines = _FileCountLines($FileLocationName) IniWrite($inifile, "config", "LastEOF", $CountLines) WEnd FileClose($file) Exitsettings.ini.txt
  23. thank you so much, smartee!
  24. sorry to trouble again. why doesn't the search and match work? #include <Array.au3> #include <File.au3> Global $inifile = @ScriptDir & "\settings.ini" Global $FileLocationName = IniRead($inifile, "config", "FileName", "FileName") Global $Temp = @ScriptDir & "\tempdb.txt" Global $extract If Not FileExists(@ScriptDir & "\settings.ini") Then $Set = FileInstall("set.ini", @ScriptDir & "\settings.ini", 1) If $Set = 0 Then MsgBox(0, "Error", "Unable to copy default settings.ini") MsgBox(0, "Missing configuration file restored", "Please update the default settings.ini before proceeding.") $NP = Run("notepad.exe " & @ScriptDir & "\settings.ini", "", @SW_MAXIMIZE) If $NP = 0 Then MsgBox(0, "Error", "Unable to open settings.ini file for modification.") Exit EndIf $Search = IniRead($inifile, "config", "Search", "Search") $i = 0 $file = FileOpen($FileLocationName, 0) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop $i += 1 $lineArr = StringSplit($line, @TAB) If ($lineArr[2] = $Search) Then ;_ArrayDisplay($lineArr, "Warning found on line: " & $i) $extract = StringRegExp($lineArr[4], "%(?:[^:]+):(.*)", 1) ;_ArrayDisplay($extract, "Extracted portion") ;MsgBox(0, "", $extract[0]) Dim $aRecords If Not _FileReadToArray($Temp, $aRecords) Then MsgBox(4096, "Error", "Error reading log to Array error: " & @error) Exit EndIf For $x = 1 To $aRecords[0] ;MsgBox(0, 'Record:' & $x, $aRecords[$x]) _ArrayToString If ($aRecords[$x] = $extract[0]) Then MsgBox(0, "", "Match") Else FileWrite($Temp, $extract[0] & @CRLF) EndIf Next EndIf WEnd FileClose($file) Exit thanks.
  25. thanks a million! appreciate it smartee!
×
×
  • Create New...