1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//! # γγΌγΉ (NΔsu)
//! π§π»ββοΈ Command-line utility which poll on remote addresses in order to perform status checks periodically
//!
//! ## Motivation
//!
//! NΔsu (from Japanese γγΌγΉ [NΔsu], which means nurse), is a command-line utility
//! to perform checks on remote addresses periodically.
//!
//! ## Usage
//!
//! Install nasu using `cargo install` command:
//!
//! ```shell
//! cargo install nasu
//! ```
//!
//! Create a `nasu.json` file and execute `nasu`.
//!
//! ## Terminology
//!
//! The following terminology is used to refer to nasu main components:
//!
//! ### Service
//!
//! Service to perform task against through the Worker, a service is created
//! from a task defined in the `nasu.json` file.
//!
//! ### Worker
//!
//! Worker in responsible of performing the task, holds the logic to interact
//! with the service in question.
//!
//! ### Task
//!
//! Defintion of steps to be performed by the worker. Is provided
//! in the `nasu.json` file.
//!
//! ### `nasu.json` Reference
//!
//! `nasu.json` is the default configuration file for Nasu. This file is
//! parsed at startup by Nasu to initialize `Workers`.
//!
//! The `nasu.json` file is composed by an array of `Task` objects as shown
//! below:
//!
//! ```json
//! // nasu.json
//! [
//! {
//! "id": "HTTPBIN POST Request",
//! "type": "http",
//! "task": {
//! "interval": "* */10 * * * *"
//! },
//! "params": {
//! "url": "http://httpbin.org/post",
//! "method": "POST",
//! "headers": {
//! "authorization": "Bearer <Token>",
//! "content-type": "application/json"
//! }
//! }
//! }
//! ]
//! ```
//!
//! Each of these `Task` must contain the following properties:
//!
//! Property | Description | Required | Possible Values
//! --- | --- | --- | ---
//! `id` | The id of the service. Used as reference for the user | Yes | N/A
//! `type` | Type of service to perform check on | Yes | `http`
//! `task` | Task configuration | Yes | N/A
//! `task.interval` | Cron defintion to specify when to perform the test | Yes | N/A
//! `params` | Params for the `Worker` used on perform. [Refer to Worker Params](#worker-params) | Yes | N/A
//!
//! ### Task `interval` field
//!
//! sec min hour day of month month day of week year
//!
//! The `interval` field on a task uses a [cron](https://en.wikipedia.org/wiki/Cron) definition.
//!
//! ```
//! βββββββββββββββ second (0 - 59)
//! β ββββββββββββββ minute (0 - 59)
//! β β ββββββββββββββ hour (0 - 23)
//! β β β ββββββββββββββ day of the month (1, 15)
//! β β β β ββββββββββββββ month (Mon, Wed, Fri)
//! β β β β β ββββββββββββββ day of the week (Mon,Wed,Fri)
//! β β β β β β βββββββββββββ year
//! β β β β β β β
//! β β β β β β β
//! * * * * * * *
//! ```
//!
//! An example:
//!
//! ```
//! 0 30 9,12,15 1,15 May-Aug Mon,Wed,Fri 2018/2
//! ```
//!
//! This application uses [cron](https://docs.rs/cron) crate internally
//! to parse and calculate time intervals.
//!
//! ### Worker Params
//!
//! `Worker` params may vary based on the `type` of worker in question.
//! Properties defined below belong to an object specified in the `Task`
//! object, inside of the `params` property.
//!
//! #### HTTP Worker Params
//!
//! - Type: `http`
//! - Property: `params`
//!
//! Property | Description | Required | Possible Values
//! --- | --- | --- | ---
//! `url` | URL to perform the HTTP Request | Yes | N/A
//! `method` | HTTP Method to perform the request with | Yes | `GET`, `PATCH`, `POST`, `PUT`, `DELETE`
//! `headers` | HTTP Headers to provide to the request | No | N/A
//!
use run;
use Builder;