Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaertschi committed May 7, 2020
0 parents commit 3ffee56
Show file tree
Hide file tree
Showing 69 changed files with 18,432 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# macOS
.DS_Store
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"semi": true,
"arrowParens": "always",
"singleQuote": false,
"trailingComma": "all"
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 zebbra AG

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 2 additions & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
backend: cd backend && PORT=3001 yarn dev
frontend: cd frontend && PORT=3000 yarn dev
2 changes: 2 additions & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PORT=3001
MERAKI_API_KEY=SECRET
64 changes: 64 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next

# moleculer build
dist
27 changes: 27 additions & 0 deletions backend/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug",
"program": "${workspaceRoot}/node_modules/moleculer/bin/moleculer-runner.ts",
"sourceMaps": true,
"runtimeArgs": ["--nolazy", "-r", "ts-node/register"],
"cwd": "${workspaceRoot}",
"args": ["--mask **/*.service.ts", "services"]
},
{
"type": "node",
"request": "launch",
"name": "Jest",
"program": "${workspaceRoot}/node_modules/jest-cli/bin/jest.js",
"args": ["--runInBand"],
"cwd": "${workspaceRoot}",
"runtimeArgs": ["--inspect-brk", "--nolazy"]
}
]
}
61 changes: 61 additions & 0 deletions backend/@types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
declare namespace MerakiRootCause {
interface IInventory {
mac: string;
serial: string;
networkId?: string;
model: string;
claimedAt: string;
publicIp?: any;
name: string;
[propName: string]: any;
}

interface IStatus {
name: string;
serial: string;
mac: string;
publicIp?: any;
networkId?: string;
status: string;
lastReportedAt?: any;
usingCellularFailover: boolean;
wan1Ip?: any;
wan2Ip?: any;
lanIp?: any;
}

export interface INetwork {
id: string;
organizationId: string;
name: string;
timeZone: string;
tags?: string;
productTypes: string[];
type: "combined" | "appliance" | "switch" | "wireless";
disableMyMerakiCom: boolean;
disableRemoteStatusPage: boolean;
}

export interface INetworkId {
netId: string;
}

export interface IOrganization {
id: string;
name: string;
}

export interface IOrganizationId {
orgId: string;
}

export interface ILicense {
status: string;
expirationDate: string;
licensedDeviceCounts: {
[x: string]: number;
};
}
}

export default MerakiRootCause;
1 change: 1 addition & 0 deletions backend/@types/json-bigint.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module "json-bigint";
44 changes: 44 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Root Cause Detection Backend

> Meraki root cause detection backend built with [Moleculer](https://moleculer.services).
[![Moleculer](https://badgen.net/badge/Powered%20by/Moleculer/0e83cd)](https://moleculer.services)

## NPM scripts

```bash
# Start development mode (load all services locally with hot-reload & REPL)
$ yarn dev

# Uses typescript to transpile service to javascript
yarn build

# Start production mode (set `SERVICES` env variable to load certain services) (previous build needed)
yarn start

# Start a CLI and connect to production. Don't forget to set production namespace with `--ns` argument in script
yarn cli

# Run TSLint
yarn lint

# Run continuous test mode with watching
yarn ci

# Run tests & generate coverage report
yarn test
```

## Requirements

- [Node.js v12](https://nodejs.org/en/)

## Development Setup

1. Copy `.env.example` to `.env` and change values accordingly
1. Run `yarn dev`

## Production

1. `yarn build`
1. `yarn start`
33 changes: 33 additions & 0 deletions backend/lib/bottleneck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Bottleneck from "bottleneck";
import Moleculer from "moleculer";

class Singleton {
static instance: Bottleneck.Group;
private logger: Moleculer.LoggerInstance;

constructor(logger: Moleculer.LoggerInstance) {
if (!Singleton.instance) {
this.logger = logger;

Singleton.instance = new Bottleneck.Group({
maxConcurrent: 5,
minTime: 200,
highWater: 1000,
});

Singleton.instance.on("created", (limiter, key) => {
this.logger.info(`A new limiter was created for "${key}"`);

limiter.on("error", (error) => {
this.logger.error("Limiter received error", error);
});
});
}
}

getInstance() {
return Singleton.instance;
}
}

export default Singleton;
3 changes: 3 additions & 0 deletions backend/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Util from "util";

export const delay = Util.promisify(setTimeout);
Loading

0 comments on commit 3ffee56

Please sign in to comment.