Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
E
energyai_java
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
葛齐林
energyai_java
Commits
8c14dc2a
Commit
8c14dc2a
authored
Mar 09, 2021
by
co_dengxiongwen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tj
parent
43e2d020
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
44 additions
and
17 deletions
+44
-17
SnmpGet.java
...main/java/com/devplatform/admin/common/utils/SnmpGet.java
+27
-4
SnmpUtil.java
...ain/java/com/devplatform/admin/common/utils/SnmpUtil.java
+2
-0
createJava.properties
microservice-admin/src/main/resources/createJava.properties
+0
-1
SpringBoot2Oauth2Application.java
...java/com/oauth/security/SpringBoot2Oauth2Application.java
+0
-1
AppLoginInSuccessHandler.java
.../com/oauth/security/handler/AppLoginInSuccessHandler.java
+10
-9
MyAuthorizationServerConfig.java
...om/oauth/security/server/MyAuthorizationServerConfig.java
+3
-0
EquipmentApplication.java
.../java/com/devplatform/equipment/EquipmentApplication.java
+2
-2
No files found.
microservice-admin/src/main/java/com/devplatform/admin/common/utils/SnmpGet.java
View file @
8c14dc2a
...
...
@@ -16,6 +16,10 @@ import org.snmp4j.smi.OctetString;
import
org.snmp4j.smi.VariableBinding
;
import
org.snmp4j.transport.DefaultUdpTransportMapping
;
/**
* SNMP又称简单网络管理协议,由一组网络管理的标准组成,
* 该协议能够支持网络管理系统,用以监测连接到网络上的设备是否有任何引起管理上关注的情况。
* 简而言之,SNMP就是为不同种类、不同厂家生产、不同型号的设备,
* 定义为一个统一的接口和协议,使得管理员可以是使用统一的方法来管理这些设备。
* @author jzj
* @date 2020/7/30 15:23
*/
...
...
@@ -32,19 +36,25 @@ public class SnmpGet {
* @return
*/
public
static
CommunityTarget
createDefault
(
String
ip
,
String
community
)
{
//生成目标地址对象
Address
address
=
GenericAddress
.
parse
(
DEFAULT_PROTOCOL
+
":"
+
ip
+
"/"
+
DEFAULT_PORT
);
//CommunityTarget类实现了Target接口,用于SNMPv1和SNMPv2c这两个版本
CommunityTarget
target
=
new
CommunityTarget
();
//设置snmp共同体
target
.
setCommunity
(
new
OctetString
(
community
));
//设置ip地址
target
.
setAddress
(
address
);
//设置使用的snmp版本
target
.
setVersion
(
DEFAULT_VERSION
);
//
milliseconds
//
超时时间
target
.
setTimeout
(
DEFAULT_TIMEOUT
);
//重传次数
target
.
setRetries
(
DEFAULT_RETRY
);
return
target
;
}
/**
* 通过任意oid
,get方式
请求服务器判断ip是否能ping通
* 通过任意oid
(对象标示符) ,get方式(get则是取具体的oid的值)
请求服务器判断ip是否能ping通
*
* @return
*/
...
...
@@ -54,21 +64,27 @@ public class SnmpGet {
target
.
setTimeout
(
timeOut
);
Snmp
snmp
=
null
;
try
{
//绑定要查询的OID
PDU
pdu
=
new
PDU
();
// pdu.add(new VariableBinding(new OID(new int[]
// {1,3,6,1,2,1,1,2})));
pdu
.
add
(
new
VariableBinding
(
new
OID
(
oid
)));
//设定采取的协议
DefaultUdpTransportMapping
transport
=
new
DefaultUdpTransportMapping
();
//创建SNMP对象,用于发送请求PDU
snmp
=
new
Snmp
(
transport
);
////调用snmp中的listen()方法,启动监听进程,接收消息,由于该监听进程是守护进程,最后应调用close()方法来释放该进程
snmp
.
listen
();
pdu
.
setType
(
PDU
.
GET
);
//调用 send(PDU pdu,Target target)发送pdu,返回一个ResponseEvent对象
ResponseEvent
respEvent
=
snmp
.
send
(
pdu
,
target
);
//通过ResponseEvent对象来获得SNMP请求的应答pdu,方法:public PDU getResponse()
PDU
response
=
respEvent
.
getResponse
();
if
(
response
==
null
)
{
}
else
{
//通过应答pdu获得mib信息(之前绑定的OID的值),方法:VaribleBinding get(int index)
for
(
int
i
=
0
;
i
<
response
.
size
();
i
++)
{
VariableBinding
vb
=
response
.
get
(
i
);
return
true
;
...
...
@@ -89,6 +105,13 @@ public class SnmpGet {
return
false
;
}
/**
* 单个oid
* @param ip
* @param community
* @param oid
* @return
*/
public
static
boolean
snmpGet
(
String
ip
,
String
community
,
String
oid
)
{
CommunityTarget
target
=
createDefault
(
ip
,
community
);
...
...
@@ -133,7 +156,7 @@ public class SnmpGet {
*
* @param ip
* @param community
* @param oid
* @param oid
List
*/
public
static
List
<
String
>
snmpGetList
(
String
ip
,
String
community
,
List
<
String
>
oidList
)
{
List
<
String
>
snmpList
=
new
ArrayList
<>();
...
...
microservice-admin/src/main/java/com/devplatform/admin/common/utils/SnmpUtil.java
View file @
8c14dc2a
...
...
@@ -168,7 +168,9 @@ public class SnmpUtil {
double
freeSize
=
Long
.
parseLong
(
values
[
1
].
getVariable
().
toString
());
// 磁盘缓存大小
double
availableSize
=
Long
.
parseLong
(
values
[
4
].
getVariable
().
toString
());
// 缓冲区大小
double
bufferSize
=
Long
.
parseLong
(
values
[
3
].
getVariable
().
toString
());
//占用内存
memory
=
(
totalSize
-
freeSize
-
availableSize
-
bufferSize
)
/
totalSize
*
100
;
break
;
}
...
...
microservice-admin/src/main/resources/createJava.properties
View file @
8c14dc2a
...
...
@@ -8,7 +8,6 @@ gpt.idleConnectionTestPeriod=60
gpt.acquireIncrement
=
3
gpt.maxIdleTime
=
60
gpt.initialPoolSize
=
10
gpt.maxPoolSize
=
100
#gpt.devPath=/Users/suochaochao/Work/sjw-cloud/microservice-spring-cloud/microservice-admin/
gpt.java.devPath
=
D:
\\
ck_work
\\
Suntray
\\
crsh_java
\\
microservice-admin
\\
src
\\
main
\\
java
\\
com
\\
devplatform
\\
admin
\\
modules
\\
gpt.xml.devPath=D:
\\
ck_work
\\
Suntray
\\
crsh_java
\\
microservice-admin
\\
src
\\
main
\\
resources
\\
...
...
microservice-authorization-server/src/main/java/com/oauth/security/SpringBoot2Oauth2Application.java
View file @
8c14dc2a
...
...
@@ -17,7 +17,6 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@SpringBootApplication
(
exclude
=
{
DataSourceAutoConfiguration
.
class
})
@Slf4j
@ComponentScan
(
basePackages
=
{
"com.oauth.security"
})
@EnableFeignClients
public
class
SpringBoot2Oauth2Application
{
...
...
microservice-authorization-server/src/main/java/com/oauth/security/handler/AppLoginInSuccessHandler.java
View file @
8c14dc2a
...
...
@@ -34,17 +34,13 @@ import org.springframework.stereotype.Component;
@Component
(
"appLoginInSuccessHandler"
)
public
class
AppLoginInSuccessHandler
extends
SavedRequestAwareAuthenticationSuccessHandler
{
@Autowired
private
ObjectMapper
objectMapper
;
@Autowired
private
ObjectMapper
objectMapper
;
@Autowired
private
PasswordEncoder
passwordEncoder
;
@Autowired
private
PasswordEncoder
passwordEncoder
;
@Autowired
private
ClientDetailsService
clientDetailsService
;
@Autowired
private
ClientDetailsService
clientDetailsService
;
@Autowired
private
AuthorizationServerTokenServices
authorizationServerTokenServices
;
@Autowired
private
AuthorizationServerTokenServices
authorizationServerTokenServices
;
@Override
public
void
onAuthenticationSuccess
(
...
...
@@ -93,6 +89,11 @@ public class AppLoginInSuccessHandler extends SavedRequestAwareAuthenticationSuc
/**
* 解码
*
* @param header
* @param request
* @return
* @throws IOException
*/
private
String
[]
extractAndDecodeHeader
(
String
header
,
HttpServletRequest
request
)
throws
IOException
{
...
...
@@ -110,7 +111,7 @@ public class AppLoginInSuccessHandler extends SavedRequestAwareAuthenticationSuc
if
(
delim
==
-
1
)
{
throw
new
BadCredentialsException
(
"Invalid basic authentication token"
);
}
else
{
return
new
String
[]{
token
.
substring
(
0
,
delim
),
token
.
substring
(
delim
+
1
)};
return
new
String
[]
{
token
.
substring
(
0
,
delim
),
token
.
substring
(
delim
+
1
)};
}
}
}
microservice-authorization-server/src/main/java/com/oauth/security/server/MyAuthorizationServerConfig.java
View file @
8c14dc2a
...
...
@@ -8,6 +8,7 @@ import java.util.List;
import
org.apache.commons.lang.ArrayUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.security.authentication.AuthenticationManager
;
...
...
@@ -41,9 +42,11 @@ public class MyAuthorizationServerConfig extends AuthorizationServerConfigurerAd
@Autowired
private
AuthenticationManager
authenticationManager
;
@Qualifier
(
"myUserDetailsServiceImpl"
)
@Autowired
private
UserDetailsService
userDetailsService
;
@Qualifier
(
"jwtTokenStore"
)
@Autowired
private
TokenStore
tokenStore
;
...
...
microservice-equipment/src/main/java/com/devplatform/equipment/EquipmentApplication.java
View file @
8c14dc2a
...
...
@@ -41,8 +41,8 @@ public class EquipmentApplication {
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
EquipmentApplication
.
class
,
args
);
handleMqInit
();
sendMsg
();
//
handleMqInit();
//
sendMsg();
}
private
static
void
handleMqInit
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment