Skip to content

Commit

Permalink
Up to the stars
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Rataj committed Nov 16, 2020
0 parents commit d96a02a
Show file tree
Hide file tree
Showing 8 changed files with 1,282 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
node_modules/
42 changes: 42 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Create a container

on:
push:
# Publish `v1.2.3` tags as releases.
tags:
- v*
jobs:

# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
push:
runs-on: ubuntu-latest
if: github.event_name == 'push'

steps:
- uses: actions/checkout@v2

- name: Build image
run: docker build . --file Dockerfile --tag image

- name: Log into registry
run: echo "${{ secrets.CR_PAT }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Push image
run: |
IMAGE_ID=ghcr.io/${{ github.repository }}
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# keep only the major.minor release, no patch
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/\.[0-9]*$//')
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag image $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
node_modules/
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

FROM node:14.13.0-alpine3.12
LABEL maintainer="Daniel Rataj <daniel.rataj@centrum.cz>"
LABEL org.opencontainers.image.source="https://github.com/whoopsmonitor/whoopsmonitor-check-json-expect"
LABEL com.whoopsmonitor.documentation="https://github.com/whoopsmonitor/whoopsmonitor-check-json-expect"
LABEL com.whoopsmonitor.env.WM_API_ENDPOINT="https://"
LABEL com.whoopsmonitor.env.WM_EXPECT="status/number/=/200"

WORKDIR /app
COPY ./src/index.js ./src/index.js
COPY ./package.json ./package.json
COPY ./package-lock.json ./package-lock.json

RUN npm install

CMD [ "npm", "start", "--silent" ]
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# whoopsmonitor-check-json-expect

Get remote JSON response and search for some specific results such as string, number.

## Environmental variables

- `WM_API_ENDPOINT` API endpoint to call.
- `WM_EXPECT` Comma separated list of items.

### WM_EXPECT

It is separated into four parts separated with a slash.

- `key` The name of the key to search in response.
- `rule`
- `string`
- `number`, `integer`
- `boolean`
- `operator`
- string
- `eq`, `=` (exact match)
- `*=` (partial match)
- numbers
- `eq`, `=` (exact match)
- `gt`, `>` - greater than (numbers)
- `lt`, `<` - lower than (numbers)
- `value` Compared value.

## Example

There is an example of the check at Whoops Monitor configuration tab or the `.env` file.

```yaml
WM_API_ENDPOINT=https://localhost:1337
WM_EXPECT=data.db/boolean/=/true
```

```yaml
WM_API_ENDPOINT=https://localhost:1337
WM_EXPECT=data.db/number/gt/100
```

## Output

- `0` - Data founded in the format as expected.
- `2` - Data does not have a proper format.

## Build

```sh
docker build -t whoopsmonitor-check-json-expect .
```

## Run

```bash
docker run --rm --env-file .env whoopsmonitor-check-json-expect
```
Loading

0 comments on commit d96a02a

Please sign in to comment.