Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions .github/workflows/discovery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ jobs:
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }} # checkout the correct branch name
fetch-depth: 0 # fetch the whole repo history
fetch-depth: 0
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}

- name: Set up Go
uses: actions/setup-go@v4
Expand Down Expand Up @@ -57,9 +58,16 @@ jobs:
output: both
thresholds: '70 80'

- name: Check if forked
id: fork_check
if: github.event_name == 'pull_request'
run: |
is_forked=$(echo "${{ github.event.pull_request.head.repo.fork }}" | tr '[:upper:]' '[:lower:]')
echo "::set-output name=is_forked::${is_forked}"

- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request'
if: ${{ github.event_name == 'pull_request' && steps.fork_check.outputs.is_forked != 'true' }}
with:
recreate: true
path: code-coverage-results.md
Expand All @@ -74,5 +82,6 @@ jobs:
path: bin

- name: Push Coverage Badge
if: ${{ steps.fork_check.outputs.is_forked != 'true' }} # skip if is a forked repo.
run: |
.github/workflows/badge.sh
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ build: fmt vet yaml2go ## Build binary for release
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -a -o bin/discovery_darwin_amd64 cli/*.go
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o bin/discovery-l cli/*.go
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -a -o bin/discovery.exe cli/*.go
# weblogic
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -a -o bin/weblogic_darwin_arm64 weblogiccli/*.go
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -a -o bin/weblogic_darwin_amd64 weblogiccli/*.go
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o bin/weblogic-l weblogiccli/*.go
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -a -o bin/weblogic.exe weblogiccli/*.go


.PHONY: yaml2go
yaml2go: yaml2go-cli ## Generate yaml config struct
Expand Down
133 changes: 133 additions & 0 deletions README_WEBLOGIC.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
![](https://img.shields.io/badge/go%20report-A+-brightgreen.svg?style=flat)
![Coverage](https://github.com/Azure/discover-java-apps/blob/badge/badge.svg?branch=badge)

## What's this project for?

A script to discover java apps from your linux system by following steps:

1. SSH login to your linux system
2. Find the process for weblogic server
3. Collect information of runtime env, configuration, jar/war/ear files
4. Print the info to console (or specified file) in json or csv format

## Download and run

Download the binary files from [releases](https://github.com/Azure/discover-java-apps/releases)

- For Linux:

```bash
weblogic-l -server 'servername' -port 'port' -username 'userwithsudo' -password 'password' -weblogicusername "weblogic" -weblogicpassword "weblogicpassword"
```

- For Windows:

```bash
weblogic.exe -server 'servername' -port 'port' -username 'userwithsudo' -password 'password' -weblogicusername "weblogic" -weblogicpassword "weblogicpassword"
```

- For Mac (Intel chip):

```bash
weblogic_darwin_amd64 -server 'servername' -port 'port' -username 'userwithsudo' -password 'password' -weblogicusername "weblogic" -weblogicpassword "weblogicpassword"
```

- For Mac (Apple silicon):

```bash
weblogic_darwin_arm64 -server 'servername' -port 'port' -username 'userwithsudo' -password 'password' -weblogicusername "weblogic" -weblogicpassword "weblogicpassword"
```

> You can find the running log from __weblogic.log__ in the same folder

## Sample output

The default output will be a json like

```javascript
[
{
"server": "20.39.48.129",
// Application Name
"appName": "shoppingcart",
"appType": "war",
// Application Port
"appPort": 7001,
// Runtime Memory
"jvmMemoryInMB": 512,
// OS Name
"osName": "ol",
// OS Version
"osVersion": "7.6",
// appliation absolute path
"jarFileLocation": "/u01/domains/adminDomain/servers/admin/upload/shoppingcart.war/app/shoppingcart.war",
"lastModifiedTime": "2023-06-01T06:04:21Z",
// Weblogic Version
"weblogicVersion": "14.1.1.0.0",
"runtimeJdkVersion": "11.0.11",
// Weblogic Patches
"weblogicPatches": "32697788;24150631;Mon Jan 09 07:56:07 UTC 2023;WLS PATCH SET UPDATE 14.1.1.0.210329\n32581868;24146453;Mon Jan 09 07:55:16 UTC 2023;Bundle patch for Oracle Coherence Version 14.1.1.0.4\n",
"deploymentTarget": "admin",
"serverType": "weblogic"
},
{
...
}
]
```

CSV format is also supported when `-format csv` is received in command arguments
```csv
Server,AppName,AppType,AppPort,JvmHeapMemory(MB),OsName,OsVersion,JarFileLocation,JarFileModifiedTime,WeblogicVersion,WeblogicPatches,DeploymentTarget,RuntimeJdkVersion,ServerType
20.39.48.129,testwebapp,war,7001,512,ol,7.6,/u01/domains/adminDomain/servers/admin/upload/testwebapp.war/app/testwebapp.war,2023-05-29T07:24:19Z,14.1.1.0.0,"32697788;24150631;Mon Jan 09 07:56:07 UTC 2023;WLS PATCH SET UPDATE 14.1.1.0.210329
32581868;24146453;Mon Jan 09 07:55:16 UTC 2023;Bundle patch for Oracle Coherence Version 14.1.1.0.4
",admin,11.0.11,weblogic
20.39.48.129,shoppingcart,war,7001,512,ol,7.6,/u01/domains/adminDomain/servers/admin/upload/shoppingcart.war/app/shoppingcart.war,2023-06-01T06:04:21Z,14.1.1.0.0,"32697788;24150631;Mon Jan 09 07:56:07 UTC 2023;WLS PATCH SET UPDATE 14.1.1.0.210329
32581868;24146453;Mon Jan 09 07:55:16 UTC 2023;Bundle patch for Oracle Coherence Version 14.1.1.0.4
",admin,11.0.11,weblogic


```

## Contributing

We appreciate your help on the java app weblogic. Before your contributing, please be noted:

1. Ensure you have Golang `1.20+` installed before starting try from source code
2. Run Makefile in `wsl` if you're Windows user
3. `70%` test coverage is mandatory in the PR build, so when you do PR, remember to include test cases as well.
4. Recommend to use [Ginkgo](https://onsi.github.io/ginkgo/) for a BDD style test case

## Build

```bash
make build
```

## Check code coverage

```bash
go tool cover -func=coverage.out | grep total: | grep -Eo '[0-9]+\.[0-9]+'
```

## Limitation

Only support to discover the weblogic apps from Linux VM

## Road map

- More java app runtime are coming.

| Type | Readiness | Ready Date |
|----------------| -- | -- |
| SpringBoot App | Ready | 2023-04 |
| WebLogic App | Alpha | 2023-06 |
| Tomcat App | Planned | - |
| WebSphere App | Planned | - |
| JBoss EAP App | Planned | - |

- More source operating systems are coming.

## Support

Report the issue to <https://github.com/Azure/azure-weblogic-java-apps/issues>
45 changes: 22 additions & 23 deletions springboot/yaml_cfg.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
package springboot

// Pattern
type Pattern struct {
Cert []string `yaml:"cert"`
Static Static `yaml:"static"`
App []string `yaml:"app"`
Logging Logging `yaml:"logging"`
}

// Static
type Static struct {
Extension []string `yaml:"extension"`
Folder []string `yaml:"folder"`
}

// Logging
type Logging struct {
ConsoleOutput ConsoleOutput `yaml:"console_output"`
FilePatterns []string `yaml:"file_patterns"`
ConsoleOutput ConsoleOutput `yaml:"console_output"`
}

// ConsoleOutput
Expand All @@ -12,17 +26,18 @@ type ConsoleOutput struct {
Yamlpath []string `yaml:"yamlpath"`
}

// Static
type Static struct {
Folder []string `yaml:"folder"`
Extension []string `yaml:"extension"`
}

// Env
type Env struct {
Denylist []string `yaml:"denylist"`
}

// YamlConfig
type YamlConfig struct {
Server Server `yaml:"server"`
Pattern Pattern `yaml:"pattern"`
Env Env `yaml:"env"`
}

// Server
type Server struct {
Connect Connect `yaml:"connect"`
Expand All @@ -33,19 +48,3 @@ type Connect struct {
Parallel bool `yaml:"parallel"`
Parallelism int `yaml:"parallelism"`
}

// YamlConfig
type YamlConfig struct {
Pattern Pattern `yaml:"pattern"`
Env Env `yaml:"env"`
Server Server `yaml:"server"`
}

// Pattern
type Pattern struct {
Logging Logging `yaml:"logging"`
Cert []string `yaml:"cert"`
Static Static `yaml:"static"`
App []string `yaml:"app"`
}

10 changes: 10 additions & 0 deletions weblogic/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package weblogic

import (
_ "embed"
)

//go:embed config.yml
var defaultConfigYaml string

var ConfigPathEnvKey = "CONFIG_PATH"
96 changes: 96 additions & 0 deletions weblogic/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
server:
connect:
parallel: true
parallelism: 50
pattern:
app:
- "application\\.ya?ml"
- "application-\\w+\\.ya?ml"
- "application\\.properties"
- "application-\\w+\\.properties"
logging:
file_patterns:
- "log4j\\.xml"
- "log4j-\\w+\\.xml"
- "log4j2\\.xml"
- "log4j2-\\w+\\.xml"
- "log4j2\\.ya?ml"
- "log4j2-\\w+\\.ya?ml"
- "log4j2\\.jso?n"
- "log4j2-\\w+\\.jso?n"
- "log4j\\.properties"
- "log4j-\\w+\\.properties"
- "log4j2\\.properties"
- "log4j2-\\w+\\.properties"
- "logback\\.xml"
- "logback-\\w+\\.xml"
console_output:
patterns:
- (?i)(appender.*=.*ConsoleAppender|appender.*\.type\s*=\s*Console)
- (?i)(<appender)([\s\S])*(ConsoleAppender|type\s*=\s*"console"|</console>)([\s\S])*(</appender)
yamlpath:
- $[*]["appenders","AppEnders"][?(@.console || @.Console || @.appender[?(@.type=~/(?i)console/)])]
cert:
- ".der"
- ".cer"
- ".pfx"
- ".p12"
- ".pem"
- ".pub"
- ".key"
- ".jks"
static:
extension:
- ".js"
- ".css"
- ".html"
- ".htm"
- ".gif"
- ".png"
- ".jpg"
- ".jpeg"
folder:
- "/META-INF/resources/"
- "/static/"
- "/public/"
env:
denylist:
- "PWD"
- "HOME"
- "SHELL"
- "LOGNAME"
- "UID"
- "HOSTNAME"
- "MAIL"
- "EDITOR"
- "TEMP"
- "LS_COLORS"
- "USER"
- "TERM"
- "LANG"
- "PATH"
- "SHLVL"
- "SSH_TTY"
- "SSH_CONNECTION"
- "SSH_CLIENT"
- "XDG_SESSION_TYPE"
- "XDG_RUNTIME_DIR"
- "XDG_SESSION_CLASS"
- "XDG_SESSION_ID"
- "SELINUX_USE_CURRENT_RANGE"
- "SELINUX_ROLE_REQUESTED"
- "SELINUX_LEVEL_REQUESTED"
- "G_BROKEN_FILENAMES"
- "QTDIR"
- "QTLIB"
- "QTINC"
- "CVS_RSH"
- "HISTSIZE"
- "HISTCONTROL"
- "LESSOPEN"
- "_"
- "MOTD_SHOWN"
- "SGX_AESM_ADDR"
- "LESSCLOSE"
- "XDG_DATA_DIRS"
- "DBUS_SESSION_BUS_ADDRESS"
Loading