Solved

I need to write a C# program that will search a certain log file on about 100 machines for certain text and output that to a table or listbox or some other output.

Posted on 2004-10-11
7
205 Views
Last Modified: 2010-04-15
I need to write a loop that will check a certain log file on about 100 machines and then in a list box print out the machine name, the last instance of the word "backup" in the log and the date following "date=" in the log.

Here is an example of the log:

<![LOG[Retrieved local Management Point from AD: BACKUP]LOG]!><time="13:16:03.645+300" date="10-11-2004" component="LocationServices" context="" type="1" thread="320" file="lsad.cpp:2514">

So what I need is:

LOOP:
Check the log file at \\machine1\C$\Windows\System32\Log\backup.log all the way through
\\machine99\C$\Windows\System32\Log\backup.log

Find last instance of the word "BACKUP" and "date=" in the log and put that into a list box or some other form of output. If "BACKUP" doesn't exist just print "No" in the listbox next to that machine name.

Hope this makes sense.

After that, I'd like to make changes to the program to allow it to interact with Active Directory and check the c:\windows\system32\Logs\backup.log on every machine in the OU that I choose.  Is that possible?

Thanks in advance,

Jake
0
Comment
Question by:jnewton03
7 Comments
 
LVL 6

Expert Comment

by:etmendz
ID: 12284846
This is usually a billable request. An entire project maybe with a deadline and, optionally, a project manager. You might also want to hire a software architect and another developer. You might also want to include your systems/infrastructure architect to offer expertise on how to make this possible on your network. Optionally, get a technical writer for the documents and a tester to complete the team.

Just kidding...

But if you can show what you've done so far then maybe we can focus on what exactly is the problem... so far, I think the problem is that you don't have the confidence to start this yourself...
0
 
LVL 11

Expert Comment

by:pratap_r
ID: 12286023
sure its possible.. and heres the code... :-)

      string mcbase="machine";
      for(int i=1; i < 100; i++)
      {
            TextReader tr=new StreamReader(@"\\"+mcbase+i+@"\c$\Windows\System32\Log\backup.log");
            string str=tr.ReadToEnd();
            Regex r=new Regex("BACKUP.*date=\"([^\"]*)\"",RegexOptions.RightToLeft);
            Match m=r.Match(str);
            if(m.Length==0)
                  MessageBox.Show("No");
            else
                  MessageBox.Show(m.Groups[1].ToString());
      }

it does a regex match agains the words backup and date="" so you might want to change that a bit to make it match better... i have tested it against the input you gave so it should work i guess. and you might want to put in some error handling also..

next for AD... post on your requirements.. sounds like fun :-)

btw, my billing rate will be 140$ per hour.. heh :-) ... just kidding

Enjoy!
Pratap
0
 

Author Comment

by:jnewton03
ID: 12288229
Thanks for the help.  The Regular Expression is always returning "No."  I'm really bad with Regular Expressions, so are you sure that's the correct format for the log I showed above?

Also, for the AD part, I'd like to show a Tree where I can click on whichever OU I want (the Domain name is IOWA) and have the program check that log on every machine in that OU and output to a table with the following columns: (Machine Name, If it has the log with the word Backup in it (yes or no), and the date).

Eventually I'd like this to be a web application so I may end up re-writing it in ASP.Net.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 11

Expert Comment

by:pratap_r
ID: 12289386
yes its exactly the same log.. i copied the log line and created a file on my drive and checked it.. can you attach a few more lines.. probably its something else

for the AD part it shouldnt be a problem... just put the above code in a function which accepts the machine name as parameter and you are good to go.. just call the function whenever you click the treeview node...

Pratap
0
 
LVL 8

Expert Comment

by:Razzie_
ID: 12290166
Unless this is for some rotten test database, you have plain SQL in your log file including columns and table names. I don't know your enviroment the application is running, but it is a bad idea to post things like this on the net since hackers love that.
0
 

Author Comment

by:jnewton03
ID: 12290560
Sorry bout that.  That was the wrong log file anyways.  Here is my log file (last few entries):

<![LOG[Current AD site of machine is Default-First-Site-Name]LOG]!><time="18:07:56.880+300" date="09-30-2004" component="LocationServices" context="" type="1" thread="388" file="lsad.cpp:215">
<![LOG[Retrieved local Management Point from AD: BACKUP]LOG]!><time="18:07:56.880+300" date="09-30-2004" component="LocationServices" context="" type="1" thread="388" file="lsad.cpp:2514">
<![LOG[Current AD site of machine is Default-First-Site-Name]LOG]!><time="18:07:56.970+300" date="09-30-2004" component="LocationServices" context="" type="1" thread="388" file="lsad.cpp:215">

Should the regular expression you showed still work?

Also, someone please let me know if this is still dangerous to post (I'm bad with SQL)


Thanks again!
Jake
0
 
LVL 11

Accepted Solution

by:
pratap_r earned 500 total points
ID: 12295050
it works fine.. this is the output i get in the message box.. exactly what you are looking for..
09-30-2004

i mean i dont see any compromising information in what you have posted so you should be safe :-)

Enjoy!
Pratap
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Problem with SqlConnection 4 159
LINQ - C# to VB convertion 12 46
Excel import error " External table is not in expected format" 12 48
Runtime Error 2 28
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now