Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/remove_matamo_ip
Browse files Browse the repository at this point in the history
  • Loading branch information
Aias00 authored Jan 17, 2025
2 parents 5910bf6 + 5c39b98 commit 25895d2
Show file tree
Hide file tree
Showing 13 changed files with 240 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.common.SshException;
import org.apache.sshd.common.channel.exception.SshChannelOpenException;
import org.apache.sshd.common.config.keys.FilePasswordProvider;
import org.apache.sshd.common.util.io.output.NoCloseOutputStream;
import org.apache.sshd.common.util.security.SecurityUtils;
import org.springframework.util.StringUtils;
Expand Down Expand Up @@ -322,7 +323,13 @@ private ClientSession getConnectSession(SshProtocol sshProtocol, int timeout, bo
clientSession.addPasswordIdentity(sshProtocol.getPassword());
} else if (StringUtils.hasText(sshProtocol.getPrivateKey())) {
var resourceKey = PrivateKeyUtils.writePrivateKey(sshProtocol.getHost(), sshProtocol.getPrivateKey());
SecurityUtils.loadKeyPairIdentities(null, () -> resourceKey, new FileInputStream(resourceKey), null)
FilePasswordProvider passwordProvider = (session, resource, index) -> {
if (StringUtils.hasText(sshProtocol.getPrivateKeyPassphrase())) {
return sshProtocol.getPrivateKeyPassphrase();
}
return null;
};
SecurityUtils.loadKeyPairIdentities(null, () -> resourceKey, new FileInputStream(resourceKey), passwordProvider)
.forEach(clientSession::addPublicKeyIdentity);
} // else auth with localhost private public key certificates

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public class SshProtocol implements CommonRequestProtocol, Protocol {
* Private key (optional)
*/
private String privateKey;

/**
* private key passphrase (optional)
*/
private String privateKeyPassphrase;

/**
* reuse connection session
Expand Down
21 changes: 21 additions & 0 deletions hertzbeat-manager/src/main/resources/define/app-almalinux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ params:
required: false
# hide param-true or false
hide: true
# field-param field key
- field: privateKeyPassphrase
# name-param field display i18n name
name:
zh-CN: 密钥短语
en-US: PrivateKey PassPhrase
# type-param field type(most mapping the html input type)
type: password
# required-true or false
required: false
# hide param-true or false
hide: true
# collect metrics config list
metrics:
# metrics - basic, inner monitoring metrics (responseTime - response time)
Expand Down Expand Up @@ -158,6 +170,8 @@ metrics:
password: ^_^password^_^
# ssh private key
privateKey: ^_^privateKey^_^
# ssh private key passphrase
privateKeyPassphrase: ^_^privateKeyPassphrase^_^
timeout: ^_^timeout^_^
reuseConnection: ^_^reuseConnection^_^
# ssh run collect script
Expand Down Expand Up @@ -226,6 +240,7 @@ metrics:
username: ^_^username^_^
password: ^_^password^_^
privateKey: ^_^privateKey^_^
privateKeyPassphrase: ^_^privateKeyPassphrase^_^
timeout: ^_^timeout^_^
reuseConnection: ^_^reuseConnection^_^
script: "LANG=C lscpu | awk -F: '$1==\"Model name\" {print $2}';awk '/processor/{core++} END{print core}' /proc/cpuinfo;uptime | sed 's/,/ /g' | awk '{for(i=NF-2;i<=NF;i++)print $i }' | xargs;vmstat 1 1 | awk 'NR==3{print $11}';vmstat 1 1 | awk 'NR==3{print $12}';vmstat 1 2 | awk 'NR==4{print $15}'"
Expand Down Expand Up @@ -293,6 +308,7 @@ metrics:
username: ^_^username^_^
password: ^_^password^_^
privateKey: ^_^privateKey^_^
privateKeyPassphrase: ^_^privateKeyPassphrase^_^
timeout: ^_^timeout^_^
reuseConnection: ^_^reuseConnection^_^
script: free -m | awk 'BEGIN{print "total used free buff_cache available"} NR==2{print $2,$3,$4,$6,$7}'
Expand Down Expand Up @@ -337,6 +353,7 @@ metrics:
username: ^_^username^_^
password: ^_^password^_^
privateKey: ^_^privateKey^_^
privateKeyPassphrase: ^_^privateKeyPassphrase^_^
timeout: ^_^timeout^_^
reuseConnection: ^_^reuseConnection^_^
script: vmstat -D | awk 'NR==1{print $1}';vmstat -D | awk 'NR==2{print $1}';vmstat 1 1 | awk 'NR==3{print $10}';vmstat 1 1 | awk 'NR==3{print $9}';vmstat 1 1 | awk 'NR==3{print $16}'
Expand Down Expand Up @@ -376,6 +393,7 @@ metrics:
username: ^_^username^_^
password: ^_^password^_^
privateKey: ^_^privateKey^_^
privateKeyPassphrase: ^_^privateKeyPassphrase^_^
timeout: ^_^timeout^_^
reuseConnection: ^_^reuseConnection^_^
script: cat /proc/net/dev | tail -n +3 | awk 'BEGIN{ print "interface_name receive_bytes transmit_bytes"} {print $1,$2,$10}'
Expand Down Expand Up @@ -423,6 +441,7 @@ metrics:
username: ^_^username^_^
password: ^_^password^_^
privateKey: ^_^privateKey^_^
privateKeyPassphrase: ^_^privateKeyPassphrase^_^
timeout: ^_^timeout^_^
reuseConnection: ^_^reuseConnection^_^
script: df -mP | tail -n +2 | awk 'BEGIN{ print "filesystem used available usage mounted"} {print $1,$3,$4,$5,$6}'
Expand Down Expand Up @@ -464,6 +483,7 @@ metrics:
username: ^_^username^_^
password: ^_^password^_^
privateKey: ^_^privateKey^_^
privateKeyPassphrase: ^_^privateKeyPassphrase^_^
timeout: ^_^timeout^_^
reuseConnection: ^_^reuseConnection^_^
script: ps aux | sort -k3nr | awk 'BEGIN{ print "pid cpu_usage mem_usage command" } {printf "%s %s %s ", $2, $3, $4; for (i=11; i<=NF; i++) { printf "%s", $i; if (i < NF) printf " "; } print ""}' | head -n 11
Expand Down Expand Up @@ -505,6 +525,7 @@ metrics:
username: ^_^username^_^
password: ^_^password^_^
privateKey: ^_^privateKey^_^
privateKeyPassphrase: ^_^privateKeyPassphrase^_^
timeout: ^_^timeout^_^
reuseConnection: ^_^reuseConnection^_^
script: ps aux | sort -k4nr | awk 'BEGIN{ print "pid cpu_usage mem_usage command" } {printf "%s %s %s ", $2, $3, $4; for (i=11; i<=NF; i++) { printf "%s", $i; if (i < NF) printf " "; } print ""}' | head -n 11
Expand Down
21 changes: 21 additions & 0 deletions hertzbeat-manager/src/main/resources/define/app-centos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ params:
required: false
# hide param-true or false
hide: true
# field-param field key
- field: privateKeyPassphrase
# name-param field display i18n name
name:
zh-CN: 密钥短语
en-US: PrivateKey PassPhrase
# type-param field type(most mapping the html input type)
type: password
# required-true or false
required: false
# hide param-true or false
hide: true
# collect metrics config list
metrics:
# metrics - basic, inner monitoring metrics (responseTime - response time)
Expand Down Expand Up @@ -159,6 +171,8 @@ metrics:
password: ^_^password^_^
# ssh private key
privateKey: ^_^privateKey^_^
# ssh private key passphrase
privateKeyPassphrase: ^_^privateKeyPassphrase^_^
timeout: ^_^timeout^_^
reuseConnection: ^_^reuseConnection^_^
# ssh run collect script
Expand Down Expand Up @@ -227,6 +241,7 @@ metrics:
username: ^_^username^_^
password: ^_^password^_^
privateKey: ^_^privateKey^_^
privateKeyPassphrase: ^_^privateKeyPassphrase^_^
timeout: ^_^timeout^_^
reuseConnection: ^_^reuseConnection^_^
script: "LANG=C lscpu | awk -F: '$1==\"Model name\" {print $2}';awk '/processor/{core++} END{print core}' /proc/cpuinfo;uptime | sed 's/,/ /g' | awk '{for(i=NF-2;i<=NF;i++)print $i }' | xargs;vmstat 1 1 | awk 'NR==3{print $11}';vmstat 1 1 | awk 'NR==3{print $12}';vmstat 1 2 | awk 'NR==4{print $15}'"
Expand Down Expand Up @@ -294,6 +309,7 @@ metrics:
username: ^_^username^_^
password: ^_^password^_^
privateKey: ^_^privateKey^_^
privateKeyPassphrase: ^_^privateKeyPassphrase^_^
timeout: ^_^timeout^_^
reuseConnection: ^_^reuseConnection^_^
script: free -m | awk 'BEGIN{print "total used free buff_cache available"} NR==2{print $2,$3,$4,$6,$7}'
Expand Down Expand Up @@ -338,6 +354,7 @@ metrics:
username: ^_^username^_^
password: ^_^password^_^
privateKey: ^_^privateKey^_^
privateKeyPassphrase: ^_^privateKeyPassphrase^_^
timeout: ^_^timeout^_^
reuseConnection: ^_^reuseConnection^_^
script: vmstat -D | awk 'NR==1{print $1}';vmstat -D | awk 'NR==2{print $1}';vmstat 1 1 | awk 'NR==3{print $10}';vmstat 1 1 | awk 'NR==3{print $9}';vmstat 1 1 | awk 'NR==3{print $16}'
Expand Down Expand Up @@ -377,6 +394,7 @@ metrics:
username: ^_^username^_^
password: ^_^password^_^
privateKey: ^_^privateKey^_^
privateKeyPassphrase: ^_^privateKeyPassphrase^_^
timeout: ^_^timeout^_^
reuseConnection: ^_^reuseConnection^_^
script: cat /proc/net/dev | tail -n +3 | awk 'BEGIN{ print "interface_name receive_bytes transmit_bytes"} {gsub(":", "", $1); print $1,$2,$10}'
Expand Down Expand Up @@ -424,6 +442,7 @@ metrics:
username: ^_^username^_^
password: ^_^password^_^
privateKey: ^_^privateKey^_^
privateKeyPassphrase: ^_^privateKeyPassphrase^_^
timeout: ^_^timeout^_^
reuseConnection: ^_^reuseConnection^_^
script: df -mP | tail -n +2 | awk 'BEGIN{ print "filesystem used available usage mounted"} {print $1,$3,$4,$5,$6}'
Expand Down Expand Up @@ -465,6 +484,7 @@ metrics:
username: ^_^username^_^
password: ^_^password^_^
privateKey: ^_^privateKey^_^
privateKeyPassphrase: ^_^privateKeyPassphrase^_^
timeout: ^_^timeout^_^
reuseConnection: ^_^reuseConnection^_^
script: ps aux | sort -k3nr | awk 'BEGIN{ print "pid cpu_usage mem_usage command" } {printf "%s %s %s ", $2, $3, $4; for (i=11; i<=NF; i++) { printf "%s", $i; if (i < NF) printf " "; } print ""}' | head -n 11
Expand Down Expand Up @@ -506,6 +526,7 @@ metrics:
username: ^_^username^_^
password: ^_^password^_^
privateKey: ^_^privateKey^_^
privateKeyPassphrase: ^_^privateKeyPassphrase^_^
timeout: ^_^timeout^_^
reuseConnection: ^_^reuseConnection^_^
script: ps aux | sort -k4nr | awk 'BEGIN{ print "pid cpu_usage mem_usage command" } {printf "%s %s %s ", $2, $3, $4; for (i=11; i<=NF; i++) { printf "%s", $i; if (i < NF) printf " "; } print ""}' | head -n 11
Expand Down
21 changes: 21 additions & 0 deletions hertzbeat-manager/src/main/resources/define/app-coreos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ params:
required: false
# hide param-true or false
hide: true
# field-param field key
- field: privateKeyPassphrase
# name-param field display i18n name
name:
zh-CN: 密钥短语
en-US: PrivateKey PassPhrase
# type-param field type(most mapping the html input type)
type: password
# required-true or false
required: false
# hide param-true or false
hide: true
# collect metrics config list
metrics:
# metrics - basic, inner monitoring metrics (responseTime - response time)
Expand Down Expand Up @@ -158,6 +170,8 @@ metrics:
password: ^_^password^_^
# ssh private key
privateKey: ^_^privateKey^_^
# ssh private key passphrase
privateKeyPassphrase: ^_^privateKeyPassphrase^_^
timeout: ^_^timeout^_^
reuseConnection: ^_^reuseConnection^_^
# ssh run collect script
Expand Down Expand Up @@ -226,6 +240,7 @@ metrics:
username: ^_^username^_^
password: ^_^password^_^
privateKey: ^_^privateKey^_^
privateKeyPassphrase: ^_^privateKeyPassphrase^_^
timeout: ^_^timeout^_^
reuseConnection: ^_^reuseConnection^_^
script: "LANG=C lscpu | awk -F: '$1==\"Model name\" {print $2}';awk '/processor/{core++} END{print core}' /proc/cpuinfo;uptime | sed 's/,/ /g' | awk '{for(i=NF-2;i<=NF;i++)print $i }' | xargs;vmstat 1 1 | awk 'NR==3{print $11}';vmstat 1 1 | awk 'NR==3{print $12}';vmstat 1 2 | awk 'NR==4{print $15}'"
Expand Down Expand Up @@ -293,6 +308,7 @@ metrics:
username: ^_^username^_^
password: ^_^password^_^
privateKey: ^_^privateKey^_^
privateKeyPassphrase: ^_^privateKeyPassphrase^_^
timeout: ^_^timeout^_^
reuseConnection: ^_^reuseConnection^_^
script: free -m | awk 'BEGIN{print "total used free buff_cache available"} NR==2{print $2,$3,$4,$6,$7}'
Expand Down Expand Up @@ -337,6 +353,7 @@ metrics:
username: ^_^username^_^
password: ^_^password^_^
privateKey: ^_^privateKey^_^
privateKeyPassphrase: ^_^privateKeyPassphrase^_^
timeout: ^_^timeout^_^
reuseConnection: ^_^reuseConnection^_^
script: vmstat -D | awk 'NR==1{print $1}';vmstat -D | awk 'NR==2{print $1}';vmstat 1 1 | awk 'NR==3{print $10}';vmstat 1 1 | awk 'NR==3{print $9}';vmstat 1 1 | awk 'NR==3{print $16}'
Expand Down Expand Up @@ -376,6 +393,7 @@ metrics:
username: ^_^username^_^
password: ^_^password^_^
privateKey: ^_^privateKey^_^
privateKeyPassphrase: ^_^privateKeyPassphrase^_^
timeout: ^_^timeout^_^
reuseConnection: ^_^reuseConnection^_^
script: cat /proc/net/dev | tail -n +3 | awk 'BEGIN{ print "interface_name receive_bytes transmit_bytes"} {print $1,$2,$10}'
Expand Down Expand Up @@ -423,6 +441,7 @@ metrics:
username: ^_^username^_^
password: ^_^password^_^
privateKey: ^_^privateKey^_^
privateKeyPassphrase: ^_^privateKeyPassphrase^_^
timeout: ^_^timeout^_^
reuseConnection: ^_^reuseConnection^_^
script: df -mP | tail -n +2 | awk 'BEGIN{ print "filesystem used available usage mounted"} {print $1,$3,$4,$5,$6}'
Expand Down Expand Up @@ -464,6 +483,7 @@ metrics:
username: ^_^username^_^
password: ^_^password^_^
privateKey: ^_^privateKey^_^
privateKeyPassphrase: ^_^privateKeyPassphrase^_^
timeout: ^_^timeout^_^
reuseConnection: ^_^reuseConnection^_^
script: ps aux | sort -k3nr | awk 'BEGIN{ print "pid cpu_usage mem_usage command" } {printf "%s %s %s ", $2, $3, $4; for (i=11; i<=NF; i++) { printf "%s", $i; if (i < NF) printf " "; } print ""}' | head -n 11
Expand Down Expand Up @@ -505,6 +525,7 @@ metrics:
username: ^_^username^_^
password: ^_^password^_^
privateKey: ^_^privateKey^_^
privateKeyPassphrase: ^_^privateKeyPassphrase^_^
timeout: ^_^timeout^_^
reuseConnection: ^_^reuseConnection^_^
script: ps aux | sort -k4nr | awk 'BEGIN{ print "pid cpu_usage mem_usage command" } {printf "%s %s %s ", $2, $3, $4; for (i=11; i<=NF; i++) { printf "%s", $i; if (i < NF) printf " "; } print ""}' | head -n 11
Expand Down
20 changes: 20 additions & 0 deletions hertzbeat-manager/src/main/resources/define/app-debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ params:
required: false
# hide param-true or false
hide: true
- field: privateKeyPassphrase
# name-param field display i18n name
name:
zh-CN: 密钥短语
en-US: PrivateKey PassPhrase
# type-param field type(most mapping the html input type)
type: password
# required-true or false
required: false
# hide param-true or false
hide: true
# collect metrics config list
metrics:
# metrics - basic, inner monitoring metrics (responseTime - response time)
Expand Down Expand Up @@ -158,6 +169,8 @@ metrics:
password: ^_^password^_^
# ssh private key
privateKey: ^_^privateKey^_^
# ssh private key passphrase
privateKeyPassphrase: ^_^privateKeyPassphrase^_^
timeout: ^_^timeout^_^
reuseConnection: ^_^reuseConnection^_^
# ssh run collect script
Expand Down Expand Up @@ -226,6 +239,7 @@ metrics:
username: ^_^username^_^
password: ^_^password^_^
privateKey: ^_^privateKey^_^
privateKeyPassphrase: ^_^privateKeyPassphrase^_^
timeout: ^_^timeout^_^
reuseConnection: ^_^reuseConnection^_^
script: "LANG=C lscpu | awk -F: '$1==\"Model name\" {print $2}';awk '/processor/{core++} END{print core}' /proc/cpuinfo;uptime | sed 's/,/ /g' | awk '{for(i=NF-2;i<=NF;i++)print $i }' | xargs;vmstat 1 1 | awk 'NR==3{print $11}';vmstat 1 1 | awk 'NR==3{print $12}';vmstat 1 2 | awk 'NR==4{print $15}'"
Expand Down Expand Up @@ -293,6 +307,7 @@ metrics:
username: ^_^username^_^
password: ^_^password^_^
privateKey: ^_^privateKey^_^
privateKeyPassphrase: ^_^privateKeyPassphrase^_^
timeout: ^_^timeout^_^
reuseConnection: ^_^reuseConnection^_^
script: free -m | awk 'BEGIN{print "total used free buff_cache available"} NR==2{print $2,$3,$4,$6,$7}'
Expand Down Expand Up @@ -337,6 +352,7 @@ metrics:
username: ^_^username^_^
password: ^_^password^_^
privateKey: ^_^privateKey^_^
privateKeyPassphrase: ^_^privateKeyPassphrase^_^
timeout: ^_^timeout^_^
reuseConnection: ^_^reuseConnection^_^
script: vmstat -D | awk 'NR==1{print $1}';vmstat -D | awk 'NR==2{print $1}';vmstat 1 1 | awk 'NR==3{print $10}';vmstat 1 1 | awk 'NR==3{print $9}';vmstat 1 1 | awk 'NR==3{print $16}'
Expand Down Expand Up @@ -376,6 +392,7 @@ metrics:
username: ^_^username^_^
password: ^_^password^_^
privateKey: ^_^privateKey^_^
privateKeyPassphrase: ^_^privateKeyPassphrase^_^
timeout: ^_^timeout^_^
reuseConnection: ^_^reuseConnection^_^
script: cat /proc/net/dev | tail -n +3 | awk 'BEGIN{ print "interface_name receive_bytes transmit_bytes"} {print $1,$2,$10}'
Expand Down Expand Up @@ -423,6 +440,7 @@ metrics:
username: ^_^username^_^
password: ^_^password^_^
privateKey: ^_^privateKey^_^
privateKeyPassphrase: ^_^privateKeyPassphrase^_^
timeout: ^_^timeout^_^
reuseConnection: ^_^reuseConnection^_^
script: df -mP | tail -n +2 | awk 'BEGIN{ print "filesystem used available usage mounted"} {print $1,$3,$4,$5,$6}'
Expand Down Expand Up @@ -464,6 +482,7 @@ metrics:
username: ^_^username^_^
password: ^_^password^_^
privateKey: ^_^privateKey^_^
privateKeyPassphrase: ^_^privateKeyPassphrase^_^
timeout: ^_^timeout^_^
reuseConnection: ^_^reuseConnection^_^
script: ps --no-headers -eo pid,%cpu,%mem,cmd --sort=-%cpu | head -n 10 | awk 'BEGIN {print "pid cpu_usage mem_usage command"} {print $1, $2, $3, $4}'
Expand Down Expand Up @@ -505,6 +524,7 @@ metrics:
username: ^_^username^_^
password: ^_^password^_^
privateKey: ^_^privateKey^_^
privateKeyPassphrase: ^_^privateKeyPassphrase^_^
timeout: ^_^timeout^_^
reuseConnection: ^_^reuseConnection^_^
script: ps --no-headers -eo pid,%cpu,%mem,cmd --sort=-%mem | head -n 10 | awk 'BEGIN {print "pid cpu_usage mem_usage command"} {print $1, $2, $3, $4}'
Expand Down
Loading

0 comments on commit 25895d2

Please sign in to comment.