This is a migrated thread and some comments may be shown as answers.

Real Time Log with Fiddler

0 Answers 272 Views
Extensions and Customization
This is a migrated thread and some comments may be shown as answers.
Syd Chino
Top achievements
Rank 1
Syd Chino asked on 13 Oct 2017, 10:02 AM

My target is to obtain a log file in real time using Fiddler, and extrapolate certain informations contained in the website, in my case, I need the Json when the expression begin with a specifc event or words.

I found the RTLogger of Eric Lawrence for the real time log, that works, after a little edit I did it on Visual Studio, the log file is created with all the information of the page (request, response, Html Code, etc.), so I need to "filter" or remove this useless information and keep only the JSON.

My code in CS project is:

using System;
using log4net;
using Fiddler;

[assembly: log4net.Config.XmlConfigurator(Watch=true)]
[assembly: Fiddler.RequiredVersion("2.4.5.0")]
namespace RTLogger
{
    public class RTLogger: IAutoTamper
    {
        private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        public void AutoTamperRequestAfter(Session oSession) { }
        public void AutoTamperRequestBefore(Session oSession) { }
        public void AutoTamperResponseAfter(Session oSession) { }
        public void AutoTamperResponseBefore(Session oSession)
        {
            log.InfoFormat("#{0}\t{1}\t{2}\t{3}\t{4}",
               oSession.id,
               oSession.fullUrl,
               oSession.responseCode,
               oSession.oResponse["JSON"],
               oSession.GetResponseBodyAsString()
               );
        }


       public void OnBeforeReturningError(Session oSession)
        {
            log.InfoFormat("#{0}\t{1}\t{2}",
               oSession.id,
               oSession.fullUrl,
               oSession.responseCode
               );
        }


        public void OnBeforeUnload()
        {
            log.Info("RTLogger Unloading");
        }


        public void OnLoad()
        {
            log.Info("RTLogger Loading");
            if (log.IsInfoEnabled) FiddlerApplication.AlertUser("RTLogger", "Logging is enabled");
        }
    }
}


It works, but as I told before, I have too many information, I need just the "JSON", in my case, I have:

2017-10-11 15:43:21,709 #65 http://tedme.cm.local/ted/direct/voice200{"action":"Connect","method":"retrieveDN","type":"rpc","tid":1,"result":{"success":true,"data":{"dnName":"0691387025","tServer":"TEST_ME","tServerHost":"megas01","tServerPort":3020,"bkpTServerHost":"megas02","bkpTServerPort":3020,"defaultQueue":"0691387099","serviceName":"119upout","tServerApplicationName":"SIPServer_TEST_ME_P","placeName":"WLACCW7ENN083","disasterRecoveryStatus":"0","switchDbID":140,"agentLogins":["8562973"],"employeeId":"X0233164","annexes":{"voice.outbound.wrap_up_time":"1000","voice.inbound.wrap_up_time":"10","voice.backoffice.wrap_up_time":"0"},"raoMode":"rao_italia","protocolCreationTimeout":0,"useProtocolCreationTimeout":false,"valid":true}}}

So in my case I need first of all delete all the HTML CODE and CSS information or keep just the response that starts with "action" or "connect" or other string.

My problem is that I don't know where I must insert this rules: in the fiddlerscript? in the CS project? In whick kind of way?

I try the replace in the fiddlerscript, but it gives me the same result with too many information.

I used:

// If content-type is HTML, then remove all DIV tags

if (oSession.oResponse.headers.ExistsAndContains("Content-Type", "html")){
// Remove any compression or chunking
oSession.utilDecodeResponse();var oBody = System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes);
// Replace all instances of the DIV tag with an empty string
var oRegEx = /<div[^>]*>(.*?)<\/div>/gi; oBody = oBody.replace(oRegEx, "");
// Set the response body to the div-less string
oSession.utilSetResponseBody(oBody);}

No luck with this code.

So, since I'm going crazy, do you have any ideas for help me?

No answers yet. Maybe you can help?

Tags
Extensions and Customization
Asked by
Syd Chino
Top achievements
Rank 1
Share this question
or