/* * SIPB service monitor: notification module * * Nickolai Zeldovich * February 2002 */ #include #include "sipbmon.h" static const char zwrite_path[] = "/usr/athena/bin/zwrite"; static str zephyr_buf (""); static timecb_t *zephyr_cb; static str notify_tostr (struct sm_service *svc, bool up) { strbuf m; m << svc->name << " on " << svc->host << ":" << svc->port << " is "; if (up) m << "back up\n"; else m << "down: " << svc->errmsg << "\n"; return m; } void notify_cons (struct sm_service *svc, bool up) { warn << notify_tostr (svc, up); } static void notify_zephyr_close (int s, bool ok) { close (s); } static void notify_zephyr_flush () { const char *argv[13]; int fds[2]; str buf = zephyr_buf; zephyr_cb = NULL; zephyr_buf = ""; if (pipe (fds) < 0) { warn << "Failed to create pipe: " << strerror (errno) << "\n"; return; } argv[0] = zwrite_path; argv[1] = "-q"; argv[2] = "-d"; argv[3] = "-n"; argv[4] = "-s"; argv[5] = "sipbmon"; argv[6] = "-c"; argv[7] = 1 ? "kolya" : "sipb-auto"; argv[8] = "-i"; argv[9] = "sipbmon"; argv[10] = "-O"; argv[11] = "auto"; argv[12] = NULL; make_async (fds[1]); close_on_exec (fds[1]); pid_t pid = spawn (argv[0], argv, fds[0]); close (fds[0]); if (pid < 0) { warn << "Failure spawning zwrite: " << strerror (errno) << "\n"; close (fds[1]); return; } net_write (fds[1], strbuf (buf).tosuio (), wrap (¬ify_zephyr_close, fds[1])); } void notify_zephyr (struct sm_service *svc, bool up) { zephyr_buf = zephyr_buf << notify_tostr (svc, up); if (zephyr_cb == NULL) zephyr_cb = delaycb (2, wrap (¬ify_zephyr_flush)); }