Commit c4887f20 authored by Bashar's avatar Bashar

Before Primary Presentation

parent 406501e0
package com.example.SnmpReciever;
import com.example.SnmpReciever.enitites.TrapData;
//import com.example.SnmpReciever.services.KafkaService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AllArgsConstructor;
import org.snmp4j.*;
import org.snmp4j.smi.UdpAddress;
import org.snmp4j.transport.DefaultUdpTransportMapping;
......@@ -13,14 +15,12 @@ import java.io.IOException;
/*@RestController
@RequestMapping("/api/product")*/
@Component
@AllArgsConstructor
public class SnmpListener implements CommandResponder {
private final KafkaTemplate<String, String> kafkaTemplate;
private final ObjectMapper objectMapper;
public SnmpListener(KafkaTemplate<String, String> kafkaTemplate, ObjectMapper objectMapper) {
this.kafkaTemplate = kafkaTemplate;
this.objectMapper = objectMapper;
}
@Override
public synchronized void processPdu(CommandResponderEvent event) {
......@@ -44,7 +44,7 @@ public class SnmpListener implements CommandResponder {
}
public void startTrapListener() {
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");
Snmp snmp = new Snmp(transport);
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;
import java.util.Map;
@RestController
@CrossOrigin("192.168.25.254:3000")
@RequestMapping("/api/rethink")
@CrossOrigin(origins = {"http://localhost:3000"})
public class RethinkController {
@Autowired
private RethinkDBService rethinkDBService;
......@@ -24,7 +24,6 @@ public class RethinkController {
public void delete(@RequestBody String id){
rethinkDBService.deleteById(id);
}
@GetMapping("/data")
public ResponseEntity<List<Map<String, Object>>> getData() {
List<Map<String, Object>> result = rethinkDBService.getData();
......
......@@ -32,9 +32,9 @@ public class KafkaConsumerSnmpApplication {
TrapData t = objectMapper.readValue(json,TrapData.class);
//Some Processing: Add this later
EnrichedTrap t2 = new EnrichedTrap(t);
//System.out.println("Not sent yet");
//sender.send(t2);
//System.out.println("Sent now!");
System.out.println("Not sent yet");
sender.send(t2);
System.out.println("Sent now!");
rethinkDBService.saveKafkaMessageToRethink(t2);
if (num == 1)
System.out.println(rethinkDBService.getData());
......
......@@ -35,9 +35,7 @@ public class RethinkDBService {
System.out.println(jsonString);
System.out.println(jsonNode);
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());
System.out.println("I am here now reem");
} catch (Exception 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