Lines Matching refs:nhdl
81 static nd_hdl_t *nhdl; variable
116 nd_error(nhdl, "Failed to stat %s (%s)", template, in read_template()
121 nd_error(nhdl, "Failed to open %s (%s)", template, in read_template()
126 nd_error(nhdl, "Failed to allocate %d bytes", statb.st_size); in read_template()
131 nd_error(nhdl, "Failed to read in template (%s)", in read_template()
154 nhdl->nh_rootdir, PP_SCRIPT); in process_template()
156 nhdl->nh_rootdir, tmpnam(NULL)); in process_template()
169 nd_debug(nhdl, "Executing %s", pp_cli); in process_template()
188 s = nd_get_boolean_prop(nhdl, SVCNAME, "config", "debug", &val); in get_svc_config()
189 nhdl->nh_debug = val; in get_svc_config()
191 s += nd_get_astring_prop(nhdl, SVCNAME, "config", "rootdir", in get_svc_config()
192 &(nhdl->nh_rootdir)); in get_svc_config()
195 nd_error(nhdl, "Failed to read retrieve service " in get_svc_config()
205 nd_cleanup(nhdl); in nd_sighandler()
214 build_headers(nd_hdl_t *nhdl, nd_ev_info_t *ev_info, email_pref_t *eprefs, in build_headers() argument
235 if ((subj_fmt = fmd_msg_gettext_key(nhdl->nh_msghdl, NULL, in build_headers()
237 nd_error(nhdl, "Failed to contruct subject format"); in build_headers()
340 send_email(nd_hdl_t *nhdl, const char *headers, const char *body, in send_email() argument
351 nd_debug(nhdl, "Sending email notification to %s", recip); in send_email()
353 nd_error(nhdl, "Failed to open pipe to %s (%s)", SENDMAIL, in send_email()
358 nd_error(nhdl, "Failed to write to pipe (%s)", strerror(errno)); in send_email()
361 nd_error(nhdl, "Failed to write to pipe (%s)", in send_email()
368 send_email_template(nd_hdl_t *nhdl, nd_ev_info_t *ev_info, email_pref_t *eprefs) in send_email_template() argument
372 if (build_headers(nhdl, ev_info, eprefs, &headers) != 0) in send_email_template()
382 nd_error(nhdl, "Failed to parse msg template"); in send_email_template()
387 send_email(nhdl, headers, msg, eprefs->ep_recips[i]); in send_email_template()
394 get_email_prefs(nd_hdl_t *nhdl, fmev_t ev, email_pref_t **eprefs) in get_email_prefs() argument
402 r = nd_get_notify_prefs(nhdl, "smtp", ev, &p_nvl, &npref); in get_email_prefs()
410 nd_error(nhdl, "Failed to retrieve notification preferences " in get_email_prefs()
416 nd_error(nhdl, "Failed to allocate space for email preferences " in get_email_prefs()
455 nd_error(nhdl, "Malformed email notification " in get_email_prefs()
457 nd_dump_nvlist(nhdl, p_nvl[0]); in get_email_prefs()
458 nd_dump_nvlist(nhdl, p_nvl[1]); in get_email_prefs()
461 nd_debug(nhdl, "Email notification is disabled"); in get_email_prefs()
465 if (nd_split_list(nhdl, arr1[0], ",", &tmparr1, &tn1) != 0 || in get_email_prefs()
466 nd_split_list(nhdl, arr2[0], ",", &tmparr2, &tn2) != 0) { in get_email_prefs()
467 nd_error(nhdl, "Error parsing \"to\" lists"); in get_email_prefs()
468 nd_dump_nvlist(nhdl, p_nvl[0]); in get_email_prefs()
469 nd_dump_nvlist(nhdl, p_nvl[1]); in get_email_prefs()
473 if ((ep->ep_num_recips = nd_merge_strarray(nhdl, tmparr1, tn1, in get_email_prefs()
475 nd_error(nhdl, "Error merging email recipient lists"); in get_email_prefs()
485 nd_split_list(nhdl, arr1[0], ",", &reparr1, &n1) != 0 || in get_email_prefs()
486 nd_split_list(nhdl, arr2[0], ",", &reparr2, &n2) != 0 || in get_email_prefs()
487 (repsz = nd_merge_strarray(nhdl, tmparr1, n1, tmparr2, n2, in get_email_prefs()
489 nd_join_strarray(nhdl, strarr, repsz, &ep->ep_reply_to) in get_email_prefs()
522 nd_error(nhdl, "Malformed email notification " in get_email_prefs()
524 nd_dump_nvlist(nhdl, p_nvl[0]); in get_email_prefs()
527 nd_debug(nhdl, "Email notification is disabled"); in get_email_prefs()
531 if (nd_split_list(nhdl, strarr[0], ",", &tmparr, &arrsz) in get_email_prefs()
533 nd_error(nhdl, "Error parsing \"to\" list"); in get_email_prefs()
578 nd_debug(nhdl, "Received event of class %s", class); in irpt_cbfunc()
580 if (get_email_prefs(nhdl, ev, &eprefs) < 0) in irpt_cbfunc()
583 if (nd_get_event_info(nhdl, class, ev, &ev_info) != 0) in irpt_cbfunc()
598 send_email_template(nhdl, ev_info, eprefs); in irpt_cbfunc()
606 nd_error(nhdl, "Malformed event: failed to retrieve " in irpt_cbfunc()
622 if ((body_fmt = fmd_msg_gettext_key(nhdl->nh_msghdl, NULL, in irpt_cbfunc()
624 nd_error(nhdl, "Failed to format message body"); in irpt_cbfunc()
640 if ((body_fmt = fmd_msg_gettext_key(nhdl->nh_msghdl, NULL, in irpt_cbfunc()
642 nd_error(nhdl, "Failed to format message body"); in irpt_cbfunc()
652 if (build_headers(nhdl, ev_info, eprefs, &headers) != 0) in irpt_cbfunc()
660 send_email(nhdl, headers, body, eprefs->ep_recips[i]); in irpt_cbfunc()
708 nd_debug(nhdl, "Received event of class %s", class); in listev_cb()
710 if (get_email_prefs(nhdl, ev, &eprefs) < 0) in listev_cb()
713 if (nd_get_event_info(nhdl, class, ev, &ev_info) != 0) in listev_cb()
722 nd_debug(nhdl, "Messaging suppressed for this event"); in listev_cb()
738 send_email_template(nhdl, ev_info, eprefs); in listev_cb()
749 if ((body = fmd_msg_gettext_nv(nhdl->nh_msghdl, NULL, in listev_cb()
751 nd_error(nhdl, "Failed to format message body"); in listev_cb()
752 nd_dump_nvlist(nhdl, ev_info->ei_payload); in listev_cb()
757 if (build_headers(nhdl, ev_info, eprefs, &headers) != 0) in listev_cb()
765 send_email(nhdl, headers, body, eprefs->ep_recips[i]); in listev_cb()
788 if ((nhdl = malloc(sizeof (nd_hdl_t))) == NULL) { in main()
793 (void) memset(nhdl, 0, sizeof (nd_hdl_t)); in main()
795 nhdl->nh_keep_running = B_TRUE; in main()
796 nhdl->nh_log_fd = stderr; in main()
797 nhdl->nh_pname = argv[0]; in main()
809 nhdl->nh_debug = B_TRUE; in main()
815 nhdl->nh_rootdir = strdup(optarg); in main()
818 free(nhdl); in main()
844 nd_daemonize(nhdl); in main()
855 nhdl->nh_evhdl = fmev_shdl_init(LIBFMEVENT_VERSION_2, NULL, NULL, NULL); in main()
856 if (nhdl->nh_evhdl == NULL) { in main()
858 nd_abort(nhdl, "failed to initialize libfmevent: %s", in main()
875 nd_abort(nhdl, "additional privileges required to run"); in main()
877 nhdl->nh_msghdl = fmd_msg_init(nhdl->nh_rootdir, FMD_MSG_VERSION); in main()
878 if (nhdl->nh_msghdl == NULL) in main()
879 nd_abort(nhdl, "failed to initialize libfmd_msg"); in main()
887 nd_debug(nhdl, "Subscribing to ireport.* events"); in main()
888 if (fmev_shdl_subscribe(nhdl->nh_evhdl, "ireport.*", irpt_cbfunc, in main()
890 nd_abort(nhdl, "fmev_shdl_subscribe failed: %s", in main()
894 nd_debug(nhdl, "Subscribing to list.* events"); in main()
895 if (fmev_shdl_subscribe(nhdl->nh_evhdl, "list.*", listev_cb, in main()
897 nd_abort(nhdl, "fmev_shdl_subscribe failed: %s", in main()
904 while (nhdl->nh_keep_running) in main()
907 free(nhdl->nh_rootdir); in main()
908 free(nhdl); in main()