Author Posts

May 9, 2017 at 6:57 pm

I'm all alone in a group where I'm becoming a one man devops crew and working on the start of some logging/monitoring scripts that I need some feedback on, so I'll get right to it.

I am doing log analysis and need to extract some information out of each log file. In this world there are 200 nodes. Each node has several subdirectories (Days), and each day has multiple log files depending on how many times they booted.

\Node001\day001\log001\Logfile.log

I'm starting with one log file and I will scale up from that. I have a start, that works but I'm pretty sure I'm going at this the wrong way.

I'm looking to the group to get some better suggestions on how to do this.

May 9, 2017 at 7:00 pm

...to do what?

You can use the Substring method (https://msdn.microsoft.com/en-us/library/aka44szs(v=vs.110).aspx) of a string.

$sub = $mystring.substring(2,4)

But I'm not sure that's what you're asking.

May 10, 2017 at 1:03 am

If you are looking on how to process these logs, you should look at Get-ChildItem and Get-Content to recurse the directory structure and open and parse the logs.

#Assuming C:\Nodes is the root of the logs
foreach ($file in (Get-ChildItem -Path C:\Nodes -Include *.log -File -Recurse)) {
    "Processing log file {0}" -f $file
    foreach ($line in Get-Content $file.FullName) {
        #Do something in each log
    }
}

May 10, 2017 at 4:32 am

Another option is using findstr and filter each log for a select text.

https://technet.microsoft.com/en-us/library/bb490907.aspx

May 10, 2017 at 4:40 pm

First, I want to say thank you to Don for all of the powershell material you have put out. The videos and books have gotten me to this point and I really appreciate all of your time and effort. I'm sure that when I actually get time to actually read the entire lunches book, and the Dev ops manifesto

My apologies that my post was so vauge and missing the GIST that I thought I attached, however after reading all of this, I am working on a new version.

Here is the old stuff..