npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

hubot-site-health-examine

v1.1.1

Published

This module examines sites you want to check whether these are connected successfully.

Readme

Hubot Site Health Examine

====

Overview

Description

  • hubotに載せてあげてください。
  • 登録したurlの生死状態を監視し、想定したステータスコードと返却値が異なる時にエラーメッセージを発言します。
  • ボットを招待したチャネルに対してのみ、ボットは監視情報を発言します。

Features

  • hubot-site-health-examineで提供する機能は以下のとおり
  1. 監視したいサイトのURLリストのCRUD管理 -> CRUD, Commandsの項目を参照
  2. 監視したいサイトを走査する監視メソッドを実行(healthExamineイベントと、Doctorクラスのいずれかで実行可能) -> Usage, Examine Methodの項目を参照

Requirement

CoffeeScript

Install

  1. npm install --save hubot-site-health-examineを実行する。(--saveはお好みで)
  2. external-scripts.json"hubot-site-health-examine"を追記する。

Usage

モジュールを読み込む

#監視したいサイトのリストを管理するクラス
Nurse = require('hubot-site-health-examine').Nurse

#Doctorクラスを使って監視メソッドを実行する場合に追記
Doctor = require('hubot-site-health-examine').Doctor

監視メソッドを実行するスクリプトを作成する

1. NurseのgetListメソッド

  • 登録した監視したいサイトのURLリストを取得する
# Nurseインスタンスを生成(robotオブジェクトを渡す)
nurse = new Nurse(robot)
# getListメソッドでURLリストを取得
list = nurse.getList()

2-1. healthExamineイベントを使った方法

  • robot.emit 'healthExamine', list, flags, msg
  • この方法では、渡したflagsの内容に従って、イベント内部であらかじめ設定された発言を行う。
引数
  • list : 監視対象のリスト
  • flags : 発言したい内容の選択([1,0,1]のようにして指定) 0:無効, 1:有効
    • 1桁目: エラー時に発言
    • 2桁目: 想定したstatusCodeと実際のstatusCodeが一致した場合に発言
    • 3桁目: 想定したstatusCodeと実際のstatusCodeが不一致の場合に発言
  • msg : robot.hearでコールバックに渡された引数。発言処理に必要(msg.send)。
サンプルコード
robot.hear /she examine e/i, (msg) ->
  nurse = new Nurse(robot)
  ###出力内容の選定###
  ###1st: error, 2nd: success, 3rd: fault###
  flags = [1,1,1] #すべての場合で発言
  list = nurse.getList()
  robot.emit 'healthExamine', list, flags, msg

2-2. Doctorクラスを使った方法

  • doctor.examine list, examineCallback, msg
  • この方法では、doctor.examineメソッドが戻り値として検査内容のオブジェクトを返す。
引数
  • list : 監視対象のリスト
  • examineCallback : 走査終了後に処理したいメソッド。ここで発言処理などを行う。
  • msg : robot.hearでコールバックに渡された引数。発言処理に必要(msg.send)。
戻り値
  • examineメソッド実行後に以下の形の戻り値がresultに渡される
# コネクションエラーの場合
message = {
  "status": "error",
  "statusCode": null,
  "discription": "ERROR: \"" + site.url + "\" Connection fail."
};

# 想定値と実際値が一致した場合
message = {
  "status": "matched",
  "statusCode": "" + res.statusCode,
  "discription": "SUCCESS: \"" + site.url + "\" has been alive :)"
};

# 想定値と実際値が不一致の場合
message = {
  "status": "unmatched",
  "statusCode": "" + res.statusCode,
  "discription": "ERROR: \"" + site.url + "\" [expect]: \"" + site.status + "\", [actual]: \"" + res.statusCode + "\""
};
サンプルコード
robot.hear /she examine d/i, (msg) ->
  doctor = new Doctor()
  nurse = new Nurse(robot)
  data = nurse.getList()
  doctor.examine data, examineCallback, msg

### callback ###
examineCallback = (result, msg) ->
  if result.status is "error"
  msg.send "#{result.discription}"
  else if result.status is "matched"
  msg.send "#{result.discription}"
  else if result.status is "unmatched"
  msg.send "#{result.discription}"

CRUD管理

  • 以下の形式で監視したいサイトのURLを登録する
  • SITE_URL: http(s)://から記述する。String型。
  • STATUS_CODE: Number型(200,404,503..etc)。
data = [
  {"url": "SITE_URL", "status": STATUS_CODE},
  {"url": "SITE_URL", "status": STATUS_CODE},
  {"url": "SITE_URL", "status": STATUS_CODE}
];

Commands

[]:省略可能, <>:引数

  • [BOT_NAME] she add <URL:string> <STATUS_CODE:int> : 検査するサイトを登録
  • [BOT_NAME] she list : 登録されたサイトをインデックス付きで表示
  • [BOT_NAME] she update <INDEX:int> <NEW_STATUS_CODE:int> : 登録されたサイトのインデックスと新しいステータスを指定して更新
  • [BOT_NAME] she remove <INDEX:int> : 登録されたサイトをインデックスを指定して削除

サンプルコマンド

  • [BOT_NAME] she examine with event : eventを使って監視メソッドを実行
  • [BOT_NAME] she examine with doctor : Doctorクラスを使って監視メソッドを実行

Licence

MIT

Author

sak39