From 7428634bf0ebfb7d9d1cd0dc04d44c6b31eb1ea3 Mon Sep 17 00:00:00 2001 From: geek Date: Wed, 28 Jun 2017 14:55:40 +0900 Subject: [PATCH] discovery --- .../overflow/module/infra/model/Infra.java | 36 ++++++++- .../module/infra/model/InfraHost.java | 16 ++-- .../module/infra/model/InfraMachine.java | 5 +- .../overflow/module/infra/model/InfraOS.java | 4 +- .../infra/model/InfraOSApplication.java | 4 +- .../module/infra/model/InfraOSDaemon.java | 4 +- .../module/infra/model/InfraOSPort.java | 4 +- .../module/infra/model/InfraService.java | 4 +- .../module/meta/model/MetaInfraVendor.java | 74 +++++++++++-------- src/main/resources/init.sql | 26 ++++--- 10 files changed, 112 insertions(+), 65 deletions(-) diff --git a/src/main/java/com/loafle/overflow/module/infra/model/Infra.java b/src/main/java/com/loafle/overflow/module/infra/model/Infra.java index 51af665..7766e43 100644 --- a/src/main/java/com/loafle/overflow/module/infra/model/Infra.java +++ b/src/main/java/com/loafle/overflow/module/infra/model/Infra.java @@ -48,7 +48,7 @@ public class Infra { } @Temporal(TemporalType.TIMESTAMP) - @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP") + @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) public Date getCreateDate() { return createDate; } @@ -57,4 +57,38 @@ public class Infra { this.createDate = createDate; } + + public static Infra CreateInfraByType(long id, Class c) { + + Infra infra = new Infra(); + infra.setChildId(id); + + MetaInfraType type = new MetaInfraType(); + if(c == InfraMachine.class) { + type.setId(1); + } + else if(c == InfraHost.class) { + type.setId(2); + } + else if(c == InfraOS.class) { + type.setId(3); + } + else if(c == InfraOSApplication.class) { + type.setId(4); + } + else if(c == InfraOSDaemon.class) { + type.setId(5); + } + else if(c == InfraOSPort.class) { + type.setId(6); + } + else if(c == InfraService.class) { + type.setId(7); + } + + infra.setType(type); + + return infra; + } + } diff --git a/src/main/java/com/loafle/overflow/module/infra/model/InfraHost.java b/src/main/java/com/loafle/overflow/module/infra/model/InfraHost.java index 265b0ad..b6dac64 100644 --- a/src/main/java/com/loafle/overflow/module/infra/model/InfraHost.java +++ b/src/main/java/com/loafle/overflow/module/infra/model/InfraHost.java @@ -11,12 +11,12 @@ import java.util.Date; public class InfraHost { private long id; private InfraOS os; - private int ip; - private int mac; + private long ip; + private long mac; private Date createDate; @Id - @Column(name = "ID", nullable = false) + @GeneratedValue(strategy= GenerationType.IDENTITY) public long getId() { return id; } @@ -37,26 +37,26 @@ public class InfraHost { @Basic @Column(name = "IP", nullable = false) - public int getIp() { + public long getIp() { return ip; } - public void setIp(int ip) { + public void setIp(long ip) { this.ip = ip; } @Basic @Column(name = "MAC", nullable = false) - public int getMac() { + public long getMac() { return mac; } - public void setMac(int mac) { + public void setMac(long mac) { this.mac = mac; } @Temporal(TemporalType.TIMESTAMP) - @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP") + @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) public Date getCreateDate() { return createDate; } diff --git a/src/main/java/com/loafle/overflow/module/infra/model/InfraMachine.java b/src/main/java/com/loafle/overflow/module/infra/model/InfraMachine.java index 14a44b8..0538ce4 100644 --- a/src/main/java/com/loafle/overflow/module/infra/model/InfraMachine.java +++ b/src/main/java/com/loafle/overflow/module/infra/model/InfraMachine.java @@ -17,7 +17,7 @@ public class InfraMachine { private Date createDate; @Id - @Column(name = "ID", nullable = false) + @GeneratedValue(strategy= GenerationType.IDENTITY) public long getId() { return id; } @@ -47,7 +47,7 @@ public class InfraMachine { } @Temporal(TemporalType.TIMESTAMP) - @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP") + @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) public Date getCreateDate() { return createDate; } @@ -57,3 +57,4 @@ public class InfraMachine { } } + diff --git a/src/main/java/com/loafle/overflow/module/infra/model/InfraOS.java b/src/main/java/com/loafle/overflow/module/infra/model/InfraOS.java index 4602ebc..557310f 100644 --- a/src/main/java/com/loafle/overflow/module/infra/model/InfraOS.java +++ b/src/main/java/com/loafle/overflow/module/infra/model/InfraOS.java @@ -19,7 +19,7 @@ public class InfraOS { private MetaInfraVendor vendor; @Id - @Column(name = "ID", nullable = false) + @GeneratedValue(strategy= GenerationType.IDENTITY) public long getId() { return id; } @@ -49,7 +49,7 @@ public class InfraOS { } @Temporal(TemporalType.TIMESTAMP) - @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP") + @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) public Date getCreateDate() { return createDate; } diff --git a/src/main/java/com/loafle/overflow/module/infra/model/InfraOSApplication.java b/src/main/java/com/loafle/overflow/module/infra/model/InfraOSApplication.java index 6d7701c..034e340 100644 --- a/src/main/java/com/loafle/overflow/module/infra/model/InfraOSApplication.java +++ b/src/main/java/com/loafle/overflow/module/infra/model/InfraOSApplication.java @@ -15,7 +15,7 @@ public class InfraOSApplication { private Date createDate; @Id - @Column(name = "ID", nullable = false) + @GeneratedValue(strategy= GenerationType.IDENTITY) public long getId() { return id; } @@ -45,7 +45,7 @@ public class InfraOSApplication { } @Temporal(TemporalType.TIMESTAMP) - @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP") + @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) public Date getCreateDate() { return createDate; } diff --git a/src/main/java/com/loafle/overflow/module/infra/model/InfraOSDaemon.java b/src/main/java/com/loafle/overflow/module/infra/model/InfraOSDaemon.java index 5238545..77d06ef 100644 --- a/src/main/java/com/loafle/overflow/module/infra/model/InfraOSDaemon.java +++ b/src/main/java/com/loafle/overflow/module/infra/model/InfraOSDaemon.java @@ -15,7 +15,7 @@ public class InfraOSDaemon { private Date createDate; @Id - @Column(name = "ID", nullable = false) + @GeneratedValue(strategy= GenerationType.IDENTITY) public long getId() { return id; } @@ -45,7 +45,7 @@ public class InfraOSDaemon { } @Temporal(TemporalType.TIMESTAMP) - @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP") + @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) public Date getCreateDate() { return createDate; } diff --git a/src/main/java/com/loafle/overflow/module/infra/model/InfraOSPort.java b/src/main/java/com/loafle/overflow/module/infra/model/InfraOSPort.java index 46a106f..6876e54 100644 --- a/src/main/java/com/loafle/overflow/module/infra/model/InfraOSPort.java +++ b/src/main/java/com/loafle/overflow/module/infra/model/InfraOSPort.java @@ -21,7 +21,7 @@ public class InfraOSPort { private boolean tlsType; @Id - @Column(name = "ID", nullable = false) + @GeneratedValue(strategy= GenerationType.IDENTITY) public long getId() { return id; } @@ -41,7 +41,7 @@ public class InfraOSPort { } @Temporal(TemporalType.TIMESTAMP) - @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP") + @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) public Date getCreateDate() { return createDate; } diff --git a/src/main/java/com/loafle/overflow/module/infra/model/InfraService.java b/src/main/java/com/loafle/overflow/module/infra/model/InfraService.java index b585918..912a821 100644 --- a/src/main/java/com/loafle/overflow/module/infra/model/InfraService.java +++ b/src/main/java/com/loafle/overflow/module/infra/model/InfraService.java @@ -21,7 +21,7 @@ public class InfraService { private boolean tlsType; @Id - @Column(name = "ID", nullable = false) + @GeneratedValue(strategy= GenerationType.IDENTITY) public long getId() { return id; } @@ -71,7 +71,7 @@ public class InfraService { } @Temporal(TemporalType.TIMESTAMP) - @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP") + @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) public Date getCreateDate() { return createDate; } diff --git a/src/main/java/com/loafle/overflow/module/meta/model/MetaInfraVendor.java b/src/main/java/com/loafle/overflow/module/meta/model/MetaInfraVendor.java index c68b7a7..a10412b 100644 --- a/src/main/java/com/loafle/overflow/module/meta/model/MetaInfraVendor.java +++ b/src/main/java/com/loafle/overflow/module/meta/model/MetaInfraVendor.java @@ -43,15 +43,6 @@ public class MetaInfraVendor { this.createDate = createDate; } -// @Basic -// @Column(name = "TYPE_ID", nullable = false) -// public int getTypeId() { -// return typeId; -// } -// -// public void setTypeId(int typeId) { -// this.typeId = typeId; -// } @ManyToOne @JoinColumn(name = "TYPE_ID", nullable=false) @@ -64,27 +55,46 @@ public class MetaInfraVendor { } -// @Override -// public boolean equals(Object o) { -// if (this == o) return true; -// if (o == null || getClass() != o.getClass()) return false; -// -// MetaInfraVendor that = (MetaInfraVendor) o; -// -// if (id != that.id) return false; -// if (typeId != that.typeId) return false; -// if (name != null ? !name.equals(that.name) : that.name != null) return false; -// if (createDate != null ? !createDate.equals(that.createDate) : that.createDate != null) return false; -// -// return true; -// } -// -// @Override -// public int hashCode() { -// int result = id; -// result = 31 * result + (name != null ? name.hashCode() : 0); -// result = 31 * result + (createDate != null ? createDate.hashCode() : 0); -// result = 31 * result + typeId; -// return result; -// } + public static MetaInfraVendor CreateInfraVendorByOS(String osName) { + + MetaInfraVendor vendor = new MetaInfraVendor(); + + + if(osName.equals("Windows")) { + vendor.setId(25); + } + else if(osName.equals("Linux")) { + vendor.setId(27); // ubuntu + } + + return vendor; + } + + public static MetaInfraVendor CreateInfraVendorByPort(int portNumber) { + return null; + } + + public static MetaInfraVendor CreateInfraVendorByService(String serviceName) { + + MetaInfraVendor vendor = new MetaInfraVendor(); + + if(serviceName.equals("mysql")) { + vendor.setId(39); + } + else if(serviceName.equals("portgresql")) { + vendor.setId(39); + } + else if(serviceName.equals("wmi")) { + vendor.setId(39); + } + else if(serviceName.equals("snmpv2")) { + vendor.setId(39); + } + else { + vendor.setId(43); // unknown + } + + + return vendor; + } } diff --git a/src/main/resources/init.sql b/src/main/resources/init.sql index 9b2079c..9baa791 100644 --- a/src/main/resources/init.sql +++ b/src/main/resources/init.sql @@ -107,6 +107,8 @@ INSERT INTO public.meta_infra_vendor (id,create_date,"name",type_id) VALUES ( 41,'2017-06-26 20:59:36.385','WMI',7); INSERT INTO public.meta_infra_vendor (id,create_date,"name",type_id) VALUES ( 42,'2017-06-26 20:59:36.414','SNMP_V2',7); +INSERT INTO public.meta_infra_vendor (id,create_date,"name",type_id) VALUES ( +43,'2017-06-27 14:32:12.506','UNKNOWN',7); INSERT INTO public.meta_crawler (id,create_date,description,"name") VALUES ( 1,'2017-06-25 17:00:43.869','WMI','WMI_CRAWLER'); @@ -252,23 +254,23 @@ INSERT INTO public."domain" (id,create_date,"name") VALUES ( INSERT INTO public.domain_member (id,create_date,domain_id,member_id) VALUES ( 1,'2017-06-26 11:27:43.023',1,1); -INSERT INTO public.api_key (id,api_key,create_date,domain_id) VALUES ( -1,'52abd6fd57e511e7ac52080027658d13','2017-06-26 13:02:28.347',1); +INSERT INTO public.api_key (api_key,create_date,domain_id) VALUES ( +'52abd6fd57e511e7ac52080027658d13','2017-06-26 13:02:28.347',1); -INSERT INTO public.noauth_probe (id,api_key,create_date,host_name,ip_address,mac_address,temp_probe_key,domain_id,probe_id,status) VALUES ( -1,'52abd6fd57e511e7ac52080027658d13','2017-06-26 12:43:46.877','snoop',3232235980,8796753988883,'1cf2555c57d511e79714080027658d13',1,NULL,3); +INSERT INTO public.noauth_probe (api_key,create_date,host_name,ip_address,mac_address,temp_probe_key,domain_id,probe_id,status) VALUES ( +'52abd6fd57e511e7ac52080027658d13','2017-06-26 12:43:46.877','snoop',3232235980,8796753988883,'1cf2555c57d511e79714080027658d13',1,NULL,3); -INSERT INTO public.probe (id,create_date,description,encryption_key,last_polling_date,next_polling_date,probe_key,domain_id,status) VALUES ( -1,'2017-06-26 12:44:59.813','snoop probe','9c8d41ab57de11e7a2c9080027658d13',NULL,NULL,'a1e1710557de11e78799080027658d13',1,1); +INSERT INTO public.probe (create_date,description,encryption_key,last_polling_date,next_polling_date,probe_key,domain_id,status) VALUES ( +'2017-06-26 12:44:59.813','snoop probe','9c8d41ab57de11e7a2c9080027658d13',NULL,NULL,'a1e1710557de11e78799080027658d13',1,1); -INSERT INTO public.infra_machine (id,create_date,meta,probe_id) VALUES ( -0,'2017-06-26 12:12:11.698',NULL,1); +INSERT INTO public.infra_machine (create_date,meta,probe_id) VALUES ( +'2017-06-26 12:12:11.698',NULL,1); -INSERT INTO public.infra (id,child_id,create_date,type_id) VALUES ( -1,0,'2017-06-26 12:12:11.809',1); +INSERT INTO public.infra (child_id,create_date,type_id) VALUES ( +0,'2017-06-26 12:12:11.809',1); -INSERT INTO public.target (id,create_date,infra_id,probe_id) VALUES ( -1,'2017-06-26 12:37:22.854',1,1); +INSERT INTO public.target (create_date,infra_id,probe_id) VALUES ( +'2017-06-26 12:37:22.854',1,1); INSERT INTO public.sensor (id,crawler_input_items,create_date,description,crawler_id,status,target_id) VALUES ( 1,NULL,'2017-06-26 20:19:07.009','My sensor',1,1,1);