Repository is archived
No release in over a year
Default database heartbeat ability
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

Build Status Vulnerabilities Gem Version Test Coverage Code Climate

Obscured::Heartbeat

Introduction

Obscured Heartbeat adds heartbeat to a separate collection for an entity (Document), the naming of the class (Mongoid Document) is used for naming the heartbeat collection, so if the class is named "Host" the collection name will end up being "host_heartbeat".

Installation

Requirements

  • activesupport
  • mongoid
  • mongoid_search
Add this line to your application's Gemfile
gem 'obscured-heartbeat'
Execute
$ bundle

Usage

Base

Use this in files where you create non-default log collections.

require 'obscured-heartbeat'

Example

Document

require 'obscured-heartbeat'

module Obscured
  class Host
    include Mongoid::Document
    include Mongoid::Timestamps
    include Obscured::Heartbeat::Tracker
    
    field :name, type: String
    field :hostname, type: String
  end
end


host = Obscured::Host.create(:name => "John Doe", :hostname => "domain.tld")
heartbeat = host.add_heartbeat(distribution: { name: 'Ubuntu', release: '19.04', codename: 'disco', description: 'Ubuntu 19.04' }, hostname: 'host.domain.tld', ip_address: '10.0.1.1', uptime: Time.now.to_i)

#returns array of heartbeats for document (proprietor)
host.get_heartbeat
host.heartbeats

#returns heartbeat by id
host.get_heartbeat(heartbeat.id.to_s)

#returns array of heartbeats by predefined params, supports pagination
host.find_heartbeats({ hostname: "domain.tld" }, { limit: 20, skip: 0, order: :created_at.desc, only: [:id, :distrubuton, :hostname, :ip_address, :uptime, :created_at, :updated_at, :proprietor] })

#retuns array of heartbeats
host.search_heartbeats("domain.tld", { limit: 20, skip: 0, order: :created_at.desc })

Service

module Obscured
  class HostHeartbeatService
    include Mongoid::Timeline::Service::Base
  end
end

module Obscured
  class PackageSynchronizer
    def initialize(host)
      @host = host
      @service = Obscured::HostHeartbeatService.new
    end

    def last_heartbeat
      @host.by(proprietor: { host_id: host.id }).last
    end
  end
end