<commit_before>
use serialize::json;
use serialize::json::{
    Boolean,
    F64,
    I64,
    Json,
    List,
    Null,
    String,
    U64,
};
use std::io;
use std::from_str::from_str;

struct Defaults {
    refresh: u64,
    interval: u64
}

static DEFAULTS: Defaults = Defaults {
    refresh: 1800,
    interval: 60
};

/// An Event: [The event data](http://sensuapp.org/docs/latest/event_data)
/// formatted as a struct.
#[deriving(Show, PartialEq)]
pub struct Event {
    client: Client,
    check: Check,
    occurrences: u64,
    action: Option<String>,
}

/// The configuration of the client that sent this event
#[deriving(Show, PartialEq)]
pub struct Client {
    name: String,
    address: String,
    subscriptions: Vec<String>,
    timestamp: i64,
    additional: Json
}

/// The client-side definition of the check plus some extra status. See the
/// [check documentation](http://sensuapp.org/docs/latest/checks) for details.
#[deriving(Show, PartialEq)]
pub struct Check {
    // client-configured things
    name: String,
    command: String,
    subscribers: Vec<String>,
    interval: i64,
    additional: Option<Json>,

    // Results, added by Sensu
    handlers: Option<Vec<String>>,
    handler: Option<String>,
    issued: i64,
    output: String,
    status: i8,
    history: Vec<String>,
    flapping: bool,
}

#[deriving(Show, PartialEq)]
pub enum SensuError {
    InitError(String),
    EventError(String)
}

pub type SensuResult<T> = Result<T, SensuError>;

/// Extract a generic JS object, given a type
/// Early return an error if it can't be extracted
macro_rules! jk(
    ($j:ident->$k:expr $p:ident) => (
        match $j.find($k) {
            Some(value) => match value {
                &$p(ref v) => v.clone(),
                _ => return Err(EventError(format!("Wrong type for '{}': {}", $k, value)))
            },
            None => return Err(EventError(format!("couldn't find {} in event", $k)))<commit_msg>Public fields can have docstrings!<commit_after>
use serialize::json;
use serialize::json::{
    Boolean,
    F64,
    I64,
    Json,
    List,
    Null,
    String,
    U64,
};
use std::io;
use std::from_str::from_str;

struct Defaults {
    refresh: u64,
    interval: u64
}

static DEFAULTS: Defaults = Defaults {
    refresh: 1800,
    interval: 60
};

/// An Event: [The event data](http://sensuapp.org/docs/latest/event_data)
/// formatted as a struct.
#[deriving(Show, PartialEq)]
pub struct Event {
    /// Client configuration
    pub client: Client,
    /// Check Configuration
    pub check: Check,
    /// Count of the number of times this event has been going continuosly
    pub occurrences: u64,
    /// One of "create", "resolve"
    pub action: Option<String>,
}

/// The configuration of the client that sent this event
#[deriving(Show, PartialEq)]
pub struct Client {
    /// The name the client registered as
    pub name: String,
    /// The address registered by the client
    pub address: String,
    /// The subscriptions the client registered for
    pub subscriptions: Vec<String>,
    pub timestamp: i64,
    /// **Everything else**
    pub additional: Json
}

/// The client-side definition of the check plus some extra status. See the
/// [check documentation](http://sensuapp.org/docs/latest/checks) for details.
#[deriving(Show, PartialEq)]
pub struct Check {
    /* ====(  client-configured things  )==== */
    /// Name of the check (from check definition)
    pub name: String,
    /// Command being executed (from check definition)
    pub command: String,
    /// Subscription channel for the check (from check definition)
    pub subscribers: Vec<String>,
    /// How often to run the check (from check definition)
    pub interval: u64,
    /// List of handlers to run when check results in an event (from check definition)
    pub handlers: Option<Vec<String>>,
    /// Single handler to run when check results in an event (from check definition)
    pub handler: Option<String>,

    /* ====(  Semi-standard client configs  )==== */
    /// Whether or not to alert (custom for sensu-handler)
    pub alert: Option<bool>,
    /// Minimum number of occurrences required to alert (custom for sensu-handler)
    pub occurrences: Option<u64>,
    /// Interval to run handlers (custom for sensu-handler)
    pub refresh: u64,

    /* ====(  Results, added by Sensu  )==== */
    /// When the check was issued (added by Sensu daemon)
    pub issued: i64,
    /// Check command output (added by Sensu daemon)
    pub output: String,
    /// Check exit status (added by Sensu daemon)
    pub status: i8,
    /// History of exit statuses (added by Sensu server)
    pub history: Vec<String>,
    /// Whether the check is currently flapping (added by Sensu server)
    pub flapping: bool,

    /// **Everything else**
    pub additional: Option<Json>,
}

#[deriving(Show, PartialEq)]
pub enum SensuError {
    InitError(String),
    EventError(String)
}

pub type SensuResult<T> = Result<T, SensuError>;


/// Extract a generic JS object, given a type
/// Early return an error if it can't be extracted
macro_rules! jk(
    ($j:ident->$k:expr $p:ident) => (
        match $j.find($k) {
            Some(value) => match value {
                &$p(ref v) => v.clone(),
                _ => return Err(EventError(format!("Wrong type for '{}': {}", $k, value)))
            },
            None => return Err(EventError(format!("couldn't find {} in event", $k)))
{'fraction_non_alphanumeric': 0.13072255929398788, 'fraction_numerical': 0.009928295642581356, 'mean_word_length': 2.8095238095238093, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5671188', 'n_tokens_mistral': 1701, 'n_tokens_neox': 1647, 'n_words': 565}