README.md in cronitor-5.1.0 vs README.md in cronitor-5.2.0
- old
+ new
@@ -1,8 +1,8 @@
# Cronitor Ruby Library
-![Test](https://github.com/cronitorio/cronitor-ruby/workflows/Test/badge.svg)
+![Tests](https://github.com/cronitorio/cronitor-ruby/workflows/Test/badge.svg)
[![Gem Version](https://badge.fury.io/rb/cronitor.svg)](https://badge.fury.io/rb/cronitor)
[Cronitor](https://cronitor.io/) provides dead simple monitoring for cron jobs, daemons, queue workers, websites, APIs, and anything else that can send or receive an HTTP request. The Cronitor Ruby library provides convenient access to the Cronitor API from applications written in Ruby. See our [API docs](https://cronitor.io/docs/api) for detailed references on configuring monitors and sending telemetry pings.
@@ -60,10 +60,12 @@
monitor.ping(state: 'complete', metrics: {count: 1000, error_count: 17})
```
## Configuring Monitors
+### Using a YAML configuration file
+
You can configure all of your monitors using a single YAML file. This can be version controlled and synced to Cronitor as part of
a deployment or build process. For details on all of the attributes that can be set, see the [Monitor API](https://cronitor.io/docs/monitor-api) documentation.
```ruby
require 'cronitor'
@@ -125,40 +127,67 @@
alerts: ['deploys-slack']
events: true # send alert when the event occurs
```
-You can also create and update monitors by calling `Monitor.put`.
+### Using `Cronitor::Monitor.put`
+You can also create and update monitors by calling `Cronitor::Monitor.put`. This method can handle multiple monitors at once and supports various configurations and options.
+
+
+#### Usage
```ruby
require 'cronitor'
+# Define monitors as an array of hashes
monitors = [
{
type: 'job',
key: 'send-customer-invoices',
schedule: '0 0 * * *',
- assertions: [
- 'metric.duration < 5 min'
- ],
+ assertions: ['metric.duration < 5 min'],
notify: ['devops-alerts-slack']
},
{
type: 'check',
key: 'Cronitor Homepage',
- request: {
- url: 'https://cronitor.io'
- },
+ request: { url: 'https://cronitor.io' },
schedule: 'every 60 seconds',
assertions: [
- 'response.code = 200',
- 'response.time < 600ms',
+ 'response.code = 200',
+ 'response.time < 600ms'
]
}
]
-Cronitor::Monitor.put(monitors)
+# Options hash with monitors array
+options = {
+ monitors: monitors,
+ format: 'json', # Optional, can be 'json' or 'yaml'
+ rollback: false, # Optional, default is false
+ timeout: 10 # Optional, specify request timeout in seconds
+}
+
+# Create or update monitors
+Cronitor::Monitor.put(options)
```
+
+#### Parameters
+- `monitors`: An array of monitor configuration hashes.
+- `options`: A hash containing:
+ - `:monitors`: An array of monitor hashes (required).
+ - `:format`: String, format of the request ('json' or 'yaml'). Default is 'json'.
+ - `:rollback`: Boolean, indicates whether to rollback on failure. Default is `false`.
+ - `:timeout`: Integer, request timeout in seconds. Falls back to `Cronitor.timeout` if not specified.
+
+#### Return Value
+Depending on the `:format` option, this method returns:
+- For JSON: An array of `Cronitor::Monitor` instances or a single instance if only one monitor is provided.
+- For YAML: The parsed response body.
+
+#### Error Handling
+- `ValidationError`: Raised when the API returns a 400 status code, indicating invalid monitor configurations.
+- `Error`: Raised for other non-successful responses, indicating issues with connecting to the Cronitor API.
### Pause, Reset, Delete
```ruby
require 'cronitor'