The latest technology trend is the conflation of mobile agent technology for high-level inference and surveillance in wireless sensor networks. Bridging the two technology contributes to the emerging areas and acquiring foremost importance in communication. The sensor nodes shift from fixed to a dynamic environment that changes rapidly becomes prone to malicious attacks. This work considers the attacks which cause the communication failure and raises the alarm for appropriate action. A scheme has been defined to collect sufficient data to identify the abnormal behaviour on sensor nodes from Network Simulator (NS-2.35) on the defined features with mobile agent based intrusion detection system (IDS) using SPIN protocol is one of the most useful data-centric routing protocols in WSNs. This work describes a novel approach for classifying attacks based on consumed energy onto different parameters. Furthermore, on the basis of attacks type, a performance matrix is computed by standard classifiers with machine learning models. An ensemble model is proposed to improve the performance of the ensemble classifiers, which yields an average accuracy of 95%. Further, K Fold cross validation has been performed to check the consistency of the proposed ensemble model.