Code Monkey home page Code Monkey logo

refana's People

Contributors

rizo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

karlem

refana's Issues

Add support for alerts

type no_data_state = [
  | `ok
  | `no_data
  | `keep_state 
  | `alerting
];
  
let no_data_state_to_yojson = (alert) =>
    switch (alert) {
    | `ok => `String("ok")
    | `no_data => `String("no_data")
    | `keep_state => `String("keep_state")
    | `alerting => `String("alerting")
    };

type execution_error_state = [
  | `no_data
  | `paused
  | `alerting
  | `ok
  | `pending
];
  
let execution_error_state_to_yojson = (error_state) =>
  switch (error_state) {
  | `no_data => `String("no_data")
  | `paused => `String("paused")
  | `alerting => `String("alerting")
  | `ok => `String("ok")
  | `pending => `String("pending")
  };

/* Operator */
type operator_type = [
  | `and_
  | `or_
];

let operator_type_to_yojson = (operator_type) =>
  switch (operator_type) {
  | `and_ => `String("and")
  | `or_ => `String("or")
  };

[@deriving (make, to_yojson { strict: false })]
type operator = {
  [@deriving.yojson.key "type"]
  [@deriving.make.default `and_]
  type_: operator_type
};

/* Reducer */
type reducer_type = [
  | `avg
  | `min
  | `max
  | `sum
  | `count
  | `last
  | `median
  | `diff
  | `percent_diff
  | `count_non_null
];
  
let reducer_type_to_yojson = (reducer) =>
  switch (reducer) {
  | `avg => `String("avg")
  | `min => `String("min")
  | `max => `String("max")
  | `sum => `String("sum")
  | `count => `String("count")
  | `last => `String("last")
  | `median => `String("median")
  | `diff => `String("diff")
  | `percent_diff => `String("percent_diff")
  | `count_non_null => `String("count_non_null")
  };

[@deriving (make, to_yojson { strict: false })]
type reducer = {
  [@deriving.yojson.key "type"]
  [@deriving.make.default `avg]
  type_: reducer_type,

  [@deriving.make.default []]
  params: list(string),
};

let reducer = (reducer_type) => { type_: reducer_type, params: [] };

/* Query */
[@deriving (make, to_yojson { strict: false })]
type query = {
  [@deriving.make.default ["A", "5m", "now"]]
  params: list(string)
};

let query = (a, b, c) => {params: [a, b, c]};

/* Evaluator */
[@deriving (make, to_yojson { strict: false })]
type evaluator = {
  [@deriving.yojson.key "type"]
  [@deriving.make.default "gt"]
  type_: string,

  [@deriving.make.default []]
  params: list(int),
};

let gt = (value) => { type_: "gt", params: [value] };
let lt = (value) => { type_: "lt", params: [value] };
let outside_range = (from_, to_) => { type_: "outside_range", params: [from_, to_] };
let within_range = (from_, to_) => { type_: "within_range", params: [from_, to_] };
let no_value = () => { type_: "no_value", params: [] };

/* Condition */
[@deriving (make, to_yojson { strict: false })]
type condition = {
  [@deriving.make.default "query"]
  type_: string,
  operator: operator,
  reducer: reducer,
  query: query,
  evaluator: evaluator,
};

[@deriving (make, to_yojson { strict: false })]
type notification = {
  /* Currently the notification with ID 1 is Slack  */
  [@deriving.make.default 1]
  id: int
};

let notifiction = make_notification;

let condition = (operator_type, reducer_type, query, evaluator) =>
    { type_: "query", operator: {type_: operator_type}, reducer: reducer(reducer_type), query, evaluator};

[@deriving (make, to_yojson { strict: false })]
type t = {
  message: string,
  name: string,
  
  [@deriving.make.default []]
  conditions: list(condition),

  [@deriving.yojson.key "executionErrorState"]
  [@deriving.make.default `alerting]
  execution_error_state: execution_error_state,
  
  [@deriving.make.default "60s"]
  frequency: string,
  
  [@deriving.yojson.key "noDataState"]
  [@deriving.make.default `ok]
  no_data_state: no_data_state,

  [@deriving.make.default [notifiction()]]
  notifications: list(notification),

  [@deriving.make.default 1]
  handler: int,
};

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.