Commit c4887f20 authored by Bashar's avatar Bashar

Before Primary Presentation

parent 406501e0
package com.example.SnmpReciever; package com.example.SnmpReciever;
import com.example.SnmpReciever.enitites.TrapData; import com.example.SnmpReciever.enitites.TrapData;
//import com.example.SnmpReciever.services.KafkaService;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AllArgsConstructor;
import org.snmp4j.*; import org.snmp4j.*;
import org.snmp4j.smi.UdpAddress; import org.snmp4j.smi.UdpAddress;
import org.snmp4j.transport.DefaultUdpTransportMapping; import org.snmp4j.transport.DefaultUdpTransportMapping;
...@@ -13,14 +15,12 @@ import java.io.IOException; ...@@ -13,14 +15,12 @@ import java.io.IOException;
/*@RestController /*@RestController
@RequestMapping("/api/product")*/ @RequestMapping("/api/product")*/
@Component @Component
@AllArgsConstructor
public class SnmpListener implements CommandResponder { public class SnmpListener implements CommandResponder {
private final KafkaTemplate<String, String> kafkaTemplate; private final KafkaTemplate<String, String> kafkaTemplate;
private final ObjectMapper objectMapper; private final ObjectMapper objectMapper;
public SnmpListener(KafkaTemplate<String, String> kafkaTemplate, ObjectMapper objectMapper) {
this.kafkaTemplate = kafkaTemplate;
this.objectMapper = objectMapper;
}
@Override @Override
public synchronized void processPdu(CommandResponderEvent event) { public synchronized void processPdu(CommandResponderEvent event) {
...@@ -44,7 +44,7 @@ public class SnmpListener implements CommandResponder { ...@@ -44,7 +44,7 @@ public class SnmpListener implements CommandResponder {
} }
public void startTrapListener() { public void startTrapListener() {
try { try {
TransportMapping<?> transport = new DefaultUdpTransportMapping(new UdpAddress("192.168.25.254/1625")); TransportMapping<?> transport = new DefaultUdpTransportMapping(new UdpAddress("192.168.26.46/1625"));
System.out.println("Listening to SNMP Trap"); System.out.println("Listening to SNMP Trap");
Snmp snmp = new Snmp(transport); Snmp snmp = new Snmp(transport);
snmp.addCommandResponder(this); snmp.addCommandResponder(this);
......
//package com.example.SnmpReciever.services;
//
//import com.fasterxml.jackson.core.JsonProcessingException;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import lombok.AllArgsConstructor;
//import org.springframework.kafka.core.KafkaTemplate;
//import org.springframework.stereotype.Service;
//
//@Service
//@AllArgsConstructor
//public class KafkaService {
// private final KafkaTemplate<String, String> kafkaTemplate;
//
// public void send(String topic,String message){
// kafkaTemplate.send(topic,message);
// }
//}
...@@ -15,8 +15,8 @@ import java.util.List; ...@@ -15,8 +15,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
@RestController @RestController
@CrossOrigin("192.168.25.254:3000")
@RequestMapping("/api/rethink") @RequestMapping("/api/rethink")
@CrossOrigin(origins = {"http://localhost:3000"})
public class RethinkController { public class RethinkController {
@Autowired @Autowired
private RethinkDBService rethinkDBService; private RethinkDBService rethinkDBService;
...@@ -24,7 +24,6 @@ public class RethinkController { ...@@ -24,7 +24,6 @@ public class RethinkController {
public void delete(@RequestBody String id){ public void delete(@RequestBody String id){
rethinkDBService.deleteById(id); rethinkDBService.deleteById(id);
} }
@GetMapping("/data") @GetMapping("/data")
public ResponseEntity<List<Map<String, Object>>> getData() { public ResponseEntity<List<Map<String, Object>>> getData() {
List<Map<String, Object>> result = rethinkDBService.getData(); List<Map<String, Object>> result = rethinkDBService.getData();
......
...@@ -32,9 +32,9 @@ public class KafkaConsumerSnmpApplication { ...@@ -32,9 +32,9 @@ public class KafkaConsumerSnmpApplication {
TrapData t = objectMapper.readValue(json,TrapData.class); TrapData t = objectMapper.readValue(json,TrapData.class);
//Some Processing: Add this later //Some Processing: Add this later
EnrichedTrap t2 = new EnrichedTrap(t); EnrichedTrap t2 = new EnrichedTrap(t);
//System.out.println("Not sent yet"); System.out.println("Not sent yet");
//sender.send(t2); sender.send(t2);
//System.out.println("Sent now!"); System.out.println("Sent now!");
rethinkDBService.saveKafkaMessageToRethink(t2); rethinkDBService.saveKafkaMessageToRethink(t2);
if (num == 1) if (num == 1)
System.out.println(rethinkDBService.getData()); System.out.println(rethinkDBService.getData());
......
...@@ -35,9 +35,7 @@ public class RethinkDBService { ...@@ -35,9 +35,7 @@ public class RethinkDBService {
System.out.println(jsonString); System.out.println(jsonString);
System.out.println(jsonNode); System.out.println(jsonNode);
System.out.println(document); System.out.println(document);
System.out.println("I am here reem " + connectionFactory.getDbName() + " " + connectionFactory.getDbTableName());
r.db(connectionFactory.getDbName()).table(connectionFactory.getDbTableName()).insert(document).run(connectionFactory.getConnection()); r.db(connectionFactory.getDbName()).table(connectionFactory.getDbTableName()).insert(document).run(connectionFactory.getConnection());
System.out.println("I am here now reem");
} catch (Exception e) { } catch (Exception e) {
System.out.println("error " + e); System.out.println("error " + e);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment