Tuesday, July 5, 2016

Splunk Enterprise Import Data From Log4Net Source

Splunk Enterprise Import Data From Log4Net Source


Splunk
Nowadays there is a business need to make systems smarter and it’s always great if you can get runtime details without fuss. Splunk provides real-time operational intelligence. I started working on Splunk because I had to integrate Splunk to read log files so that we can keep an eye on business execution and a few notifications as well as alerts. Notification could be some business interruption, error emails or some blooper or some wrongdoing within the  happened and the system stopped execution. Splunk helps users in various other ways so that if something goes wrong then the end user can take adequate action to resolve issues or acknowledge them to the team or respective clients. We can also manage a dashboard to make it easier for the user who is handling the Splunk interface.
Splunk helps to collect and index data and performs indexing of data regardless of format or location – like logs, clickstreams, webservers, stream network traffic, custom application, social media and cloud services. Splunk helps you to gain valuable operational intelligence from machine generated data and with a complete range of search with visualization. Some key features are shown below.
In this article I’m going to choose log4net as a data source and will try to bring information from source and will try to show it on the main page. In order  to achieve that kindly follow the steps down the page.
Go to start button and choose Splunk enterprise or type Splunk in start -> run as shown in depicted screen shot and click on Splunk enterprise.

It will open the following window.

Image result for step2 icon: Click on Settings menu and you will see the following screen and choose data input from there

Image result for step3 icon As soon as you click on Data inputs it will take you on the screen as given below. Choose Files and directories and click.

Image result for step4 icon After clicking on files and directories it takes you to the another window to select New source as shown in below screen.

Image result for step5 iconClick on new, it will open the following window. Fill the required details specially the Files and Directory path using browse button.

Kindly go through the following screens, see how  I mapped the specific directory path; and click on the “Next” button in order to proceed further.


Image result for step6 iconKindly follow the following screens to get it done.


Click On and Start searching. The flowing window will appear. Put your search string in search box.

The above screen shot has lots of potential data which I can’t share with you. However the one is displaying "Logged in Sucessfully” fetching information from “CustomLogForSplunk”. It is also showing in source type as well. This is how it made it easy to trace each and every line of log directory of specific files. In coming articles we may have a look bout more clean and optimized searches and some visualization techniques. Until then stay tuned and happy splunking.

Splunk helps with monitoring and analyzing everything from customer click streams and transactions, stream network traffic to security events and network activity.

Apply Caching In Web API Using CacheCow

Apply Caching In Web API Using CacheCow


In this post, I’ll share about EntityTag caching in Web API. Caching always plays a vital role when we have very frequent requests for model to server, which stores loads of potential information and removes the need to hit server again and again, which helps to enhance Web API performance and reduce the load on server hosting the API. EntityTag is an HttpHeader used for cache conditional requests for resource. EntityTag is also pronounced as ETag.
Let’s take a simple example which use an ETag like “Client sends a request to Http server with Etag value" that holds an updated value for cached resource. The server identifies this with ETag value whether client has an already updated value or it should revert with a latest copy back to client.
ETag's working behavior and implementation
This section elaborates about ETag and its working behavior. Actually ETag is a string representation which is created by server against each request for a resource and also varies as value is updated for resource. For example, 
Initially client sends a request http://localhost:57888/api2/employees/getdetails/5 to server and ask for employeeId 5, as per initial request it won’t be cached and server will return the fresh copy of the requested resource with some ETag value. We’ll see this in illustrations further down in this article. Later client sends the same request to server with header If-None-Matchalong with ETag value which client has received in body response of earlier (e.g. TR6truy7) request If server finds equal ETag value for the requested resource than server responds Http not modified otherwise server will respond with new ETag value.Header “If-None-Match” works only with HttpGet and HttpDelete.
Let’s look in practical implementation. This is the simple structure of an application as given below in image:
solution
Install of CacheCow library: Kindly find the below screen shots to install CacheCow server from NuGet package manager.
NuGet
Click on install button as shown in above screenshot. As soon as you install the CacheCow you will see,
CacheCow.Common.dll and CacheCow.Server dll as depicted in screen below:
CacheCow.Common
Once the installation has done, we need to register CacheCow handler in WebApiConfig.cs file like shown below in depicted image.
execute
  1. //Way to register CacheCowHandler in WebApi.Config file
  2. var objCacheCow = new CacheCow.Server.CachingHandler(config,""); 
  3. config.MessageHandlers.Add(objCacheCow); 
You can read more about how handler works in ASP.NET Web API from here: Global and Per-Route Handler in ASP.NET Web API
The above register CacheCow handler scrutinizes each request and response and verifies the ETag value whether it matches with earlier request or it’s a completely new request. We will see this complete step by step process to understand this here. I’m using fiddler for this purpose.
Step 1: Send the Initial request using fiddler as shown below and press execute,
execute
There is a point of consideration as the response received from server in respect to the request sent by client as shown below in image contains Response Header HTTP 200 OK with the ETag value (a unique representation of each resource).
output
Step 2: We will utilize this ETag value for further communication in order to identify that whether the requested resource exists in the same form or has been changed. If the client sends frequent requesst to server for the same resource than same ETag value will be returned for this request which means no one has updated the value for requested resource.
Note: Kindly send If-None-match parameter in header of request.
header
Output will be like this as shown in given below link:
output
Step 3:
So send the new request using the ETag value received in response of last request as shown in depicted image below. For this purpose, I’ve made slight change in collection that existed in code behind and it should return the updated response value. New ETag value ensures that the requested resource has been changed at server placed in in-memory,
parsed
The above request sends the following output as in the following image:
output
The above image simply states that there is no chanes at server side for this resource. This is how we can manage In-memory caching in Web API and utilize this feature.
feature
Caching plays a vital role where client sends very frequent requess for a resource. CacheCow is one of the good providers to maintain caching in solutions though there are lots of other variants that exist. It is simple in use, easy to install and works very effectively. The one downside which I realized is that you have to keep the updated value of specific ETag sent by server response for each request.
You can download the source code from here : Apply Caching In Web API Using CacheCow

javascript hoisting

Java script hoisting Interview question

clip_image002

var a = "global Variable";

        function dotnetpiper() {
            console.log(a);
            var a = "local Variable";
            function z() {
                var a = "Inner local Variable";
                console.log(a);
            }
            z();

            console.log(a);
        }
        dotnetpiper();

Answer:

image

:

Tuesday, May 31, 2016

Web API to return JSON instead of XML

Web API to return JSON instead of XML

Concert crowd

Out of the box Web API generates XML as a result however if there is need for JSON as response than a little change may help you as given below:


Kinly open WebApiConfig.cs file add the following code segment depicted below in red:

public static void Register(HttpConfiguration config)
      {
          config.Services.Replace(typeof(IHttpControllerSelector), new CustomControllerSelector((config)));
                    
          config.Routes.MapHttpRoute(
              name: "Version1",
              routeTemplate: "api/v1/{controller}/{action}/{id}",
              defaults: new { controller = "Employees", Action = "FetchEmployeeById", id = RouteParameter.Optional }
          );

//To produce JSON format add this line of code

config.Formatters.JsonFormatter.SupportedMediaTypes.Add(newMediaTypeHeaderValue("text/html"));

}

Hope it will help you.

Learn more about MVC and WebApi :

http://www.dotnetpiper.com/search/label/MVC

http://www.dotnetpiper.com/search/label/WCF%20and%20WebAPI

Wednesday, May 18, 2016

[Error-Messages%255B2%255D.png]

"Attempt by method 'System.Web.Http.GlobalConfiguration..cctor()' to access field 'System.Web.Http.GlobalConfiguration.CS$<>9__CachedAnonymousMethodDelegate2' failed."

Hi Amigo’s

Today when i was working on WebAPi and enabling CORS for WebAPI ,i confronted an error which took time to resolve and finally resolved.

To mitigate such issue you should have to install one of the possible insatalltion using NuGet Package Manager console.

Go to NuGet Package Manager console and select Default Project in which you would like to get this feature enabled and run the following command as shown below.

Install-Package Microsoft.AspNet.WebApi –IncludePrerelease

image

I will resolve an error and will help to proceed further with you business logic.

To know more MVC and WebApi Kindly go through with these links

MVC Articles & WCF and WebAPI

Thanks

Saturday, April 16, 2016

Ensure that HttpConfiguration.EnsureInitialized() is called in the application's startup

This error prompts you when you forget to initialize the apllication startup to fix this problem kindly use the given below line and add it under global.asax file of solution.

   GlobalConfiguration.Configuration.EnsureInitialized();

image

This is the complete stack trace which comes when you run an application.

<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>
The object has not yet been initialized. Ensure that HttpConfiguration.EnsureInitialized() is called in the application's startup code after all other initialization code.
</ExceptionMessage>
<ExceptionType>System.InvalidOperationException</ExceptionType>

<StackTrace>
at System.Web.Http.Routing.RouteCollectionRoute.get_SubRoutes() at System.Web.Http.Routing.RouteCollectionRoute.GetRouteData(String virtualPathRoot, HttpRequestMessage request) at System.Web.Http.WebHost.Routing.HttpWebRoute.GetRouteData(HttpContextBase httpContext)
</StackTrace>

</Error>

Hope it will sort out your issue.

Learn more about MVC and WebApi :

http://www.dotnetpiper.com/search/label/MVC

http://www.dotnetpiper.com/search/label/WCF%20and%20WebAPI

Tuesday, April 12, 2016

Explore Persistence Caching In Web API Using CacheCow.Server.EntityTagStore.SqlServer

Concert crowd

In the previous post Apply Caching in Web API Using CacheCow, I have shared about apply caching in-memory using CacheCow and its benefits. In the continuation of that post I’ll sharethoughts about persistence caching and its implementation. Caching always plays vital role when we have very frequent request model to server to fetch the data. Caching helps to reduce frequent hits to server and brings potential information in a minimal duration. Caching also helps to enhance Web API performance and reduce the load on server where Web API is hosted? EntityTag is an HttpHeader used for cache conditional request for resource.EntityTag is also pronounced as ETag.

Let’s take a simple example which uses ETag like “Client sends a request to Http server with Etag value that holds an updated value for cached resource, server identifies this with ETag value whether client has an already updated value for resource or it should revert with a latest copy back to client.

ETag working behavior and implementation

This section elaborates about ETag and its working behavior. Actually ETag is a string representation which is created by server against each request for a resource and also varies as value is updated for resource. For example,

Initially client sends a request http://localhost:57888/api2/employees/getdetails/5 to server and ask for employeeId 5, as per initial request it won’t be cached and server will return the fresh copy of the requested resource with some ETag value. We’ll see this in illustration down the level of this article. Later client send the same request to server with header If-None-Matchalong with ETag value which client has received in body response of earlier (e.g. TR6truy7) request If server finds equal ETag value for the requested resource than server responds Http not modified otherwise server will respond with new ETag value. Header “If-None-Match” works only with HttpGet and HttpDelete.

Installation of SqlServerEntityTagStore

HttpGet and HttpDelete works in similar manner. ThoughHttpPut works slightly in different nature. For this purpose we’ve to install “CacheCow.Server.EntityTagStore.SqlServer” from NuGet manager. Right click on solution and choose manage NuGet Manager.

Manager

Type CacheCow.Server.EntityTagStore.SqlServer in search, the following window will appears shown below. Click on install button.

install

Install of CacheCow library: Click on install button as show on above screen. As soon as you install the CacheCowlibrary you will findCacheCow.Server.EntityTagStore.SqlServer.dllin solution explorer under reference folder as depicted in screen below:

reference

Once the installation has done, we need to register CacheCowSQlServerEntitytagStore handler in WebApiConfig.cs file like shown below in depicted image.

installation

  1. //Configure HTTP Caching SqlServerEntityTagStore using Entity Tags
  2. varconnString = System.Configuration.ConfigurationManager.ConnectionStrings["CacheCowConnectionString"].ConnectionString; 
  3. vareTagStore = new CacheCow.Server.EntityTagStore.SqlServer.SqlServerEntityTagStore(connString); 
  4. varcacheCowCacheHandler = newCacheCow.Server.CachingHandler(config,eTagStore,""); 
  5. cacheCowCacheHandler.AddLastModifiedHeader = false; 
  6. config.MessageHandlers.Add(cacheCowCacheHandler); 

You can read more about how does handler works in ASP.NET Web API from here: Global and Per-Route Handler in Asp.Net WebApi

Once we are have done with installation and code segment placing, next step is to execute the following database script placed under {ProjectPath}\packages\CacheCow.Server.EntityTagStore.SqlServer.1.0.0\scripts.Onceexecute the database script there will be a table dbo.CacheState and 6 procedures as shown in depicted image below:

procedures

Each procedure works in different manner. Now I’ll perform PUT HTTP PUT request to understand how persistence caching works does.

We will see this complete step by step process to understand this here. I’m using fiddler for this purpose.

Step 1: Send the Initial request using Postman as shown below and press send button:

send

Response from server as given below in screen shot:

server

As soon as you receive a response for the latest request sent by client, there will be an entry relevant to resource in CacheState table exist in database as shown below in screen shot, and which is self-explanatory.

explantory

Step 2:
We will utilize this recently received ETag value for further communication in order to update the record using HTTP PUT verb.

Note
:
Kindly send If-Match parameterin header of request to update the resource. Kindly refer the image shown below: If- Match has the value "07aa73fe997d4c199f9b4774007778ac" which is sent by the server in last request.

CacheState
The status 200 means resource has updated .

Step 3:
In these steps the main objective is to identify that, does client has the latest copy of resource or not, which client is willing to update. So send the new request using the ETag value (not latest one) received in some old response. In short If the ETag value doesn’t match with the ETag value persist in database than will revert precompiled condition issue in response .Which means that client doesn’t have the latest copy to update the resource. So please get the latest copy of resource(Using HTTP GET) before sending the update request. Kindly refer the image shown below:

request

If I use the latest Etag value than it works fine and update the value.
done

Caching plays a vital role where client sends very frequent request for a resource. CacheCow one of the good providers to maintain caching in solution though there are lots of other variants exist. It is simple in use easy to install and works very effectively. The one fall point which I realized is that you have to keep the updated value of specific ETag sent by server response for each request

You can download the source code from link given below: 

Explore Persistence Caching In Web API Using CacheCow.Server.EntityTagStore.SqlServer

Learn more about MVC and WebApi :

http://www.dotnetpiper.com/search/label/MVC

 http://www.dotnetpiper.com/search/label/WCF%20and%20WebAPI

Saturday, April 9, 2016

The request contains an entity body but no Content-Type header
The Simple solution for such issue is please put “ Content-Type: application/json; charset=utf-8” in request.
Kinldy find a screen shot given below for reference:
image
Please refer www.dotnetpiper.com