diff --git a/.drone.yml b/.drone.yml index 309ffb4..4e3c264 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,12 +1,96 @@ kind: pipeline -name: default +type: docker +name: linux-amd64 + +platform: + os: linux + arch: amd64 steps: + - name: build + image: node:alpine + commands: + - npm install + - npm run build:ssr - name: docker image: plugins/docker settings: + auto_tag: true + auto_tag_suffix: linux-amd64 repo: samuelph/cachet-monitor username: from_secret: USERNAME password: - from_secret: PASSWORD \ No newline at end of file + from_secret: PASSWORD + +trigger: + branch: + - master + event: + - push + +--- +kind: pipeline +type: docker +name: linux-arm + +platform: + os: linux + arch: arm + +steps: + - name: build + image: node:alpine + commands: + - npm install + - npm run build:ssr + - name: docker + image: plugins/docker + settings: + auto_tag: true + auto_tag_suffix: linux-arm + repo: samuelph/cachet-monitor + username: + from_secret: USERNAME + password: + from_secret: PASSWORD + when: + branch: + - master + event: + - push + +--- +kind: pipeline +type: docker +name: manifest + +platform: + os: linux + arch: arm + +steps: + - name: publish + image: plugins/manifest + settings: + auto_tag: true + ignore_missing: true + target: samuelph/cachet-monitor + template: samuelph/cachet-monitor:OS-ARCH + platforms: + - linux/amd64 + - linux/arm + username: + from_secret: USERNAME + password: + from_secret: PASSWORD + +depends_on: + - linux-amd64 + - linux-arm + +trigger: + branch: + - master + event: + - push diff --git a/Dockerfile b/Dockerfile index 3541f50..16fcebb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:13-alpine +FROM node:14.5.0-alpine MAINTAINER mail@sp-codes.de @@ -11,4 +11,4 @@ RUN mkdir -p /monitor/data \ && npm install \ && apk del git -CMD ["node", "index.js"] \ No newline at end of file +CMD ["node", "index.js"] diff --git a/README.md b/README.md index 49ecae3..53aed5d 100644 --- a/README.md +++ b/README.md @@ -95,9 +95,11 @@ services: ```bash npm run start ``` + + __Important: If you want `UDP` checks, you need to run it as `root`, because `nmap` allows `UDP` scans only for `root`.__ ## License [![GNU GPLv3 Image](https://www.gnu.org/graphics/gplv3-127x51.png)](https://www.gnu.org/licenses/gpl-3.0) -cachet-monitor is Free Software: It is licensed under GNU GPL v3 (See [LICENSE](LICENSE) for more information). \ No newline at end of file +cachet-monitor is Free Software: It is licensed under GNU GPL v3 (See [LICENSE](LICENSE) for more information). diff --git a/index.js b/index.js index d6ab8f0..7a8df3c 100644 --- a/index.js +++ b/index.js @@ -57,26 +57,32 @@ const checkHttp = async (url, performanceTimeout, requestTimeout) => { const checkPort = async (host, port, type, performanceTimeout, requestTimeout) => { return await new Promise(resolve => { nmap.scan({ + flags: ['-Pn'], range: [host], ports: port.toString(), timeout: requestTimeout, udp: type === 'udp' }, (error, report) => { - if (error) { - resolve({status: "OFFLINE", message: error}); - } else { - const result = report[host].host[0]; - const time = parseInt(result.item.endtime) - parseInt(result.item.starttime); - const status = result.ports[0].port[0].state[0].item; - if (status.state.includes('open')) { - if (time > performanceTimeout * 1000) { - resolve({status: "SLOW", message: status.state}); - } else { - resolve({status: "ONLINE", message: status.state}); - } + try { + if (error) { + resolve({status: "OFFLINE", message: error}); } else { - resolve({status: "OFFLINE", message: status.state}); + const result = report[host].host[0]; + const time = parseInt(result.item.endtime) - parseInt(result.item.starttime); + const status = result.ports[0].port[0].state[0].item; + if (status.state.includes('open')) { + if (time > performanceTimeout * 1000) { + resolve({status: "SLOW", message: status.state}); + } else { + resolve({status: "ONLINE", message: status.state}); + } + } else { + resolve({status: "OFFLINE", message: status.state}); + } } + } catch (e) { + console.error(e); + resolve({status: "OFFLINE", message: 'an unexpected error occurred'}); } }); }); diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..7e23eca --- /dev/null +++ b/renovate.json @@ -0,0 +1,9 @@ +{ + "assignees": [ + "samuel-p" + ], + "baseBranches": [ + "master" + ], + "rangeStrategy": "bump" +}