66 |
static void doGet(HttpRequest, HttpResponse); |
static void doGet(HttpRequest, HttpResponse); |
67 |
static void doPost(HttpRequest, HttpResponse); |
static void doPost(HttpRequest, HttpResponse); |
68 |
static void do_home(HttpRequest, HttpResponse); |
static void do_home(HttpRequest, HttpResponse); |
69 |
|
static void do_home_device(HttpRequest, HttpResponse); |
70 |
|
static void do_home_directory(HttpRequest, HttpResponse); |
71 |
|
static void do_home_file(HttpRequest, HttpResponse); |
72 |
|
static void do_home_process(HttpRequest, HttpResponse); |
73 |
static void do_about(HttpRequest, HttpResponse); |
static void do_about(HttpRequest, HttpResponse); |
74 |
static void not_found(HttpRequest, HttpResponse); |
static void not_found(HttpRequest, HttpResponse); |
75 |
static void do_runtime(HttpRequest, HttpResponse); |
static void do_runtime(HttpRequest, HttpResponse); |
77 |
static void handle_action(HttpRequest, HttpResponse); |
static void handle_action(HttpRequest, HttpResponse); |
78 |
static void print_status(Process_T, HttpResponse res); |
static void print_status(Process_T, HttpResponse res); |
79 |
static void is_monit_running(HttpRequest, HttpResponse); |
static void is_monit_running(HttpRequest, HttpResponse); |
80 |
static void do_process(HttpRequest, HttpResponse, char *); |
static void do_task(HttpRequest, HttpResponse, char *); |
81 |
|
static void do_task_device(HttpRequest, HttpResponse, Process_T); |
82 |
|
static void do_task_directory(HttpRequest, HttpResponse, Process_T); |
83 |
|
static void do_task_file(HttpRequest, HttpResponse, Process_T); |
84 |
|
static void do_task_process(HttpRequest, HttpResponse, Process_T); |
85 |
|
|
86 |
extern ssl_server_connection * mySSLServerConnection; |
extern ssl_server_connection * mySSLServerConnection; |
87 |
|
|
211 |
|
|
212 |
static void do_home(HttpRequest req, HttpResponse res) { |
static void do_home(HttpRequest req, HttpResponse res) { |
213 |
|
|
|
int on= TRUE; |
|
|
struct myprocess *p; |
|
214 |
char *uptime= get_process_uptime(Run.pidfile); |
char *uptime= get_process_uptime(Run.pidfile); |
215 |
|
|
|
if ( Run.doprocess ) { |
|
216 |
HEAD("", Run.polltime) |
HEAD("", Run.polltime) |
217 |
out_print(res, |
out_print(res, |
218 |
"<table cellspacing=\"0\" cellpadding=\"5\" width=\"100%%\" border=\"0\">" |
"<table cellspacing=\"0\" cellpadding=\"5\" width=\"100%%\" border=\"0\">" |
219 |
" <tr bgcolor=\"#BBDDFF\">" |
" <tr bgcolor=\"#BBDDFF\">" |
220 |
" <td colspan=2 valign=\"top\" align=\"left\" bgcolor=\"#EFF7FF\" width=\"100%%\">" |
" <td colspan=2 valign=\"top\" align=\"left\" bgcolor=\"#EFF7FF\" width=\"100%%\">" |
221 |
" <br><h2 align=\"center\">Monit Process Manager</h2>" |
" <br><h2 align=\"center\">Monit Service Manager</h2>" |
222 |
" <p align=\"center\">Monit is <a href='/_runtime'>running</a> on %s " |
" <p align=\"center\">Monit is <a href='/_runtime'>running</a> on %s " |
223 |
" with <i>uptime, %s</i> and monitoring:</p><br>" |
" with <i>uptime, %s</i> and monitoring:</p><br>" |
224 |
" </td>" |
" </td>" |
225 |
" </tr>" |
" </tr>" |
226 |
"</table>" |
"</table>" |
227 |
"<table cellspacing=\"0\" cellpadding=\"0\" width=\"100%%\" border=\"0\">" |
"<table cellspacing=\"0\" cellpadding=\"0\" width=\"100%%\" border=\"0\">" |
228 |
" <tr valign=\"middle\" bgcolor=\"#6F6F6F\">" |
" <tr valign=\"middle\" bgcolor=\"#6F6F6F\">" |
229 |
" <td><img src=\"/_pixel\" width=\"1\" height=\"1\" alt=\"\"></td>" |
" <td><img src=\"/_pixel\" width=\"1\" height=\"1\" alt=\"\"></td>" |
230 |
" </tr>" |
" </tr>" |
231 |
"</table>" |
"</table>", Run.localhostname, uptime); |
|
"<br><p> </p>" |
|
|
"<table cellspacing=0 cellpadding=3 border=0 width=\"70%\">" |
|
|
"<tr><td><h3><b>Server</b></h3></td>" |
|
|
"<td align=\"right\"><h3><b>Status</b></h3></td>" |
|
|
"<td align=\"right\"><h3><b>Uptime</b></h3></td>" |
|
|
"<td align=\"right\"><h3><b>CPU</b></h3></td>" |
|
|
"<td align=\"right\"><h3><b>Memory</b></h3></td>" |
|
|
"</tr>" |
|
|
"<tr><td> </td><td> </td></tr>", Run.localhostname, uptime); |
|
|
} else { |
|
|
HEAD("", Run.polltime) |
|
|
out_print(res, |
|
|
"<table cellspacing=\"0\" cellpadding=\"5\" width=\"100%%\" border=\"0\">" |
|
|
" <tr bgcolor=\"#BBDDFF\">" |
|
|
" <td colspan=2 valign=\"top\" align=\"left\" bgcolor=\"#EFF7FF\" width=\"100%%\">" |
|
|
" <br><h2 align=\"center\">Monit Process Manager</h2>" |
|
|
" <p align=\"center\">Monit is <a href='/_runtime'>running</a> on %s " |
|
|
" with <i>uptime, %s</i> and monitoring:</p><br>" |
|
|
" </td>" |
|
|
" </tr>" |
|
|
"</table>" |
|
|
"<table cellspacing=\"0\" cellpadding=\"0\" width=\"100%%\" border=\"0\">" |
|
|
" <tr valign=\"middle\" bgcolor=\"#6F6F6F\">" |
|
|
" <td><img src=\"/_pixel\" width=\"1\" height=\"1\" alt=\"\"></td>" |
|
|
" </tr>" |
|
|
"</table>" |
|
|
"<br><p> </p>" |
|
|
"<table cellspacing=0 cellpadding=3 border=0 width=\"70%\">" |
|
|
"<tr><td><h3><b>Server</b></h3></td>" |
|
|
"<td align=\"right\"><h3><b>Status</b></h3></td></tr>" |
|
|
"<tr><td> </td><td> </td></tr>", Run.localhostname, uptime); |
|
|
} |
|
232 |
|
|
233 |
free(uptime); |
free(uptime); |
|
|
|
|
for (p= processlist; p; p= p->next) { |
|
|
|
|
|
int isrunning= is_process_running(p); |
|
|
char *uptime= get_process_uptime(p->pidfile); |
|
234 |
|
|
235 |
if ( Run.doprocess ) { |
do_home_process(req, res); |
236 |
ProcInfo_T pi= p->procinfo; |
do_home_device(req, res); |
237 |
if ( isrunning ) { |
do_home_file(req, res); |
238 |
out_print(res,"<tr %s><td><a href='/%s'>%s</a></td><td align=\"right\">" |
do_home_directory(req, res); |
239 |
"%s</td><td align=\"right\">%s</td>" |
|
|
"<td align=\"right\">%.1f%%</td>" |
|
|
"<td align=\"right\">%.1f%% [%ldkB]</td></tr>", |
|
|
on?"bgcolor=\"#EFEFEF\"":"", |
|
|
p->name, p->name, |
|
|
p->has_checksum_error? |
|
|
"<font color='#ff0000'>Cheksum Error</font>": |
|
|
isrunning? |
|
|
"<font color=green>running</font>": |
|
|
"<font color=red>not running</font>", |
|
|
uptime, |
|
|
pi->cpu_percent/10.0, |
|
|
pi->mem_percent/10.0,pi->mem_kbyte |
|
|
); |
|
|
} else { |
|
|
out_print(res,"<tr %s><td><a href='/%s'>%s</a></td>" |
|
|
"<td align=\"right\">%s</td>" |
|
|
"<td align=\"right\">-</td>" |
|
|
"<td align=\"right\">- </td>" |
|
|
"<td align=\"right\">- [-]</td></tr>", |
|
|
on?"bgcolor=\"#EFEFEF\"":"", |
|
|
p->name, p->name, |
|
|
p->has_checksum_error? |
|
|
"<font color='#ff0000'>Cheksum Error</font>": |
|
|
"<font color=red>not running</font>" |
|
|
); |
|
|
} |
|
|
} else { |
|
|
out_print(res,"<tr %s><td><a href='/%s'>%s</a></td><td align=\"right\">" |
|
|
"%s %s</td></tr>", |
|
|
on?"bgcolor=\"#EFEFEF\"":"", |
|
|
p->name, p->name, |
|
|
p->has_checksum_error? |
|
|
"<font color='#ff0000'>Cheksum Error</font>": |
|
|
isrunning? |
|
|
"<font color=green>running</font>": |
|
|
"<font color=red>not running</font>", |
|
|
isrunning?uptime:""); |
|
|
} |
|
|
|
|
|
|
|
|
on= on?FALSE:TRUE; |
|
|
free(uptime); |
|
|
|
|
|
} |
|
|
out_print(res, "</table>"); |
|
240 |
FOOT |
FOOT |
241 |
|
|
242 |
} |
} |
451 |
|
|
452 |
if(action) { |
if(action) { |
453 |
|
|
454 |
struct myprocess *p= get_process(name); |
Process_T p= get_process(name); |
455 |
|
|
456 |
if( IS(action, "start") ) { |
if( IS(action, "start") ) { |
457 |
|
|
517 |
} |
} |
518 |
|
|
519 |
LOCK(Run.mutex) |
LOCK(Run.mutex) |
520 |
do_process(req, res, name); |
do_task(req, res, name); |
521 |
END_LOCK; |
END_LOCK; |
522 |
|
|
523 |
} else { |
} else { |
533 |
} |
} |
534 |
|
|
535 |
|
|
536 |
static void do_process(HttpRequest req, HttpResponse res, char *name) { |
static void do_task(HttpRequest req, HttpResponse res, char *name) { |
537 |
|
|
538 |
struct myprocess *p= get_process(name); |
Process_T p= get_process(name); |
|
int run= is_process_running(p); |
|
539 |
|
|
540 |
HEAD(name, 1000) |
HEAD(name, 1000) |
541 |
|
|
542 |
|
switch (p->task) { |
543 |
|
|
544 |
|
case TASK_DEVICE: |
545 |
|
do_task_device(req, res, p); |
546 |
|
break; |
547 |
|
|
548 |
|
case TASK_DIRECTORY: |
549 |
|
do_task_directory(req, res, p); |
550 |
|
break; |
551 |
|
|
552 |
|
case TASK_FILE: |
553 |
|
do_task_file(req, res, p); |
554 |
|
break; |
555 |
|
|
556 |
|
case TASK_PROCESS: |
557 |
|
do_task_process(req, res, p); |
558 |
|
break; |
559 |
|
|
560 |
|
default: |
561 |
|
break; |
562 |
|
|
563 |
|
} |
564 |
|
|
565 |
|
FOOT |
566 |
|
|
567 |
|
} |
568 |
|
|
569 |
|
|
570 |
|
static void print_status(Process_T p, HttpResponse res) { |
571 |
|
|
572 |
|
pid_t pid= -1; |
573 |
|
FILE *out= res->outputstream; |
574 |
|
struct stat stat_buf; |
575 |
|
|
576 |
|
res->is_committed= TRUE; |
577 |
|
|
578 |
|
switch(p->task) { |
579 |
|
|
580 |
|
case TASK_PROCESS: |
581 |
|
|
582 |
|
if((pid= is_process_running(p))) { |
583 |
|
|
584 |
|
char *uptime= get_process_uptime(p->path); |
585 |
|
char buf[STRLEN]; |
586 |
|
ProcInfo_T pi= p->procinfo; |
587 |
|
|
588 |
|
if ( Run.doprocess ) { |
589 |
|
|
590 |
|
sprintf(buf, |
591 |
|
"Process '%s' is running with pid [%d]\n\tUptime: %s " |
592 |
|
"CPU: %.1f%% Memory w/o children: %.1f%% [%ldkB]\n" |
593 |
|
"\tChildren: %i Memory w/ children: %.1f%% [%ldkB]\n" |
594 |
|
"\tMonitoring status: %s\n", |
595 |
|
p->name, (int)pid, uptime, pi->cpu_percent/10.0, |
596 |
|
pi->mem_percent/10.0,pi->mem_kbyte, |
597 |
|
pi->children,pi->total_mem_percent/10.0,pi->total_mem_kbyte, |
598 |
|
statusnames[p->do_validate]); |
599 |
|
|
600 |
|
} else { |
601 |
|
|
602 |
|
sprintf(buf, |
603 |
|
"Process '%s' is running with pid [%d]\n\tUptime: %s " |
604 |
|
"\tMonitoring status: %s\n", |
605 |
|
p->name, (int)pid, uptime,statusnames[p->do_validate]); |
606 |
|
|
607 |
|
} |
608 |
|
|
609 |
|
if( Run.httpdssl ) { |
610 |
|
|
611 |
|
printf_ssl_socket(res->ssl, "%s", buf); |
612 |
|
|
613 |
|
} else { |
614 |
|
|
615 |
|
fprintf(out, "%s", buf); |
616 |
|
|
617 |
|
} |
618 |
|
|
619 |
|
free(uptime); |
620 |
|
|
621 |
|
} else { |
622 |
|
|
623 |
|
if( Run.httpdssl ) { |
624 |
|
|
625 |
|
printf_ssl_socket(res->ssl, "Process '%s' is not running\n", p->name); |
626 |
|
|
627 |
|
} else { |
628 |
|
|
629 |
|
fprintf(out, "Process '%s' is not running\n", p->name); |
630 |
|
|
631 |
|
} |
632 |
|
|
633 |
|
} |
634 |
|
break; |
635 |
|
|
636 |
|
case TASK_DEVICE: |
637 |
|
if(get_fsusage(p->path, p->devinfo)) { |
638 |
|
|
639 |
|
if(p->devinfo->f_files > 0) { |
640 |
|
|
641 |
|
if( Run.httpdssl ) { |
642 |
|
|
643 |
|
printf_ssl_socket(res->ssl, "Device '%s' is accessible\n\t" |
644 |
|
"Space: %.1f%% [%.1f MB] Inodes: %.1f%% [%ld objects]\n\t" |
645 |
|
"Monitoring status: %s\n", |
646 |
|
p->name, |
647 |
|
(float) 100 * (p->devinfo->f_blocks - p->devinfo->f_blocksfree) / p->devinfo->f_blocks, |
648 |
|
(float) (p->devinfo->f_blocks - p->devinfo->f_blocksfree) / 1048576 * p->devinfo->f_bsize, |
649 |
|
(float) 100 * (p->devinfo->f_files - p->devinfo->f_filesfree) / p->devinfo->f_files, |
650 |
|
p->devinfo->f_files - p->devinfo->f_filesfree, |
651 |
|
statusnames[p->do_validate]); |
652 |
|
|
653 |
|
} else { |
654 |
|
|
655 |
|
fprintf(out, "Device '%s' is accessible\n\t" |
656 |
|
"Space: %.1f%% [%.1f MB] Inodes: %.1f%% [%ld objects]\n\t" |
657 |
|
"Monitoring status: %s\n", |
658 |
|
p->name, |
659 |
|
(float) 100 * (p->devinfo->f_blocks - p->devinfo->f_blocksfree) / p->devinfo->f_blocks, |
660 |
|
(float) (p->devinfo->f_blocks - p->devinfo->f_blocksfree) / 1048576 * p->devinfo->f_bsize, |
661 |
|
(float) 100 * (p->devinfo->f_files - p->devinfo->f_filesfree) / p->devinfo->f_files, |
662 |
|
p->devinfo->f_files - p->devinfo->f_filesfree, |
663 |
|
statusnames[p->do_validate]); |
664 |
|
|
665 |
|
} |
666 |
|
|
667 |
|
} else { |
668 |
|
|
669 |
|
if( Run.httpdssl ) { |
670 |
|
|
671 |
|
printf_ssl_socket(res->ssl, "Device '%s' is accessible\n\t" |
672 |
|
"Space: %.1f%% [%.1f MB]\n\t" |
673 |
|
"Monitoring status: %s\n", |
674 |
|
p->name, |
675 |
|
(float) 100 * (p->devinfo->f_blocks - p->devinfo->f_blocksfree) / p->devinfo->f_blocks, |
676 |
|
(float) (p->devinfo->f_blocks - p->devinfo->f_blocksfree) / 1048576 * p->devinfo->f_bsize, |
677 |
|
statusnames[p->do_validate]); |
678 |
|
|
679 |
|
} else { |
680 |
|
|
681 |
|
fprintf(out, "Device '%s' is accessible\n\t" |
682 |
|
"Space: %.1f%% [%.1f MB]\n\t" |
683 |
|
"Monitoring status: %s\n", |
684 |
|
p->name, |
685 |
|
(float) 100 * (p->devinfo->f_blocks - p->devinfo->f_blocksfree) / p->devinfo->f_blocks, |
686 |
|
(float) (p->devinfo->f_blocks - p->devinfo->f_blocksfree) / 1048576 * p->devinfo->f_bsize, |
687 |
|
statusnames[p->do_validate]); |
688 |
|
|
689 |
|
} |
690 |
|
|
691 |
|
} |
692 |
|
|
693 |
|
} else { |
694 |
|
|
695 |
|
if( Run.httpdssl ) { |
696 |
|
|
697 |
|
printf_ssl_socket(res->ssl, "Device '%s' is not accessible\n\t" |
698 |
|
"Space: - Inodes: -\n\t" |
699 |
|
"Monitoring status: %s\n", |
700 |
|
p->name, statusnames[p->do_validate]); |
701 |
|
|
702 |
|
} else { |
703 |
|
|
704 |
|
fprintf(out, "Device '%s' is not accessible\n\t" |
705 |
|
"Space: - Inodes: -\n\t" |
706 |
|
"Monitoring status: %s\n", |
707 |
|
p->name, statusnames[p->do_validate]); |
708 |
|
|
709 |
|
} |
710 |
|
|
711 |
|
} |
712 |
|
|
713 |
|
break; |
714 |
|
|
715 |
|
case TASK_FILE: |
716 |
|
if( (stat(p->path, &stat_buf) == 0) && S_ISREG(stat_buf.st_mode) ) { |
717 |
|
if( Run.httpdssl ) { |
718 |
|
|
719 |
|
printf_ssl_socket(res->ssl, |
720 |
|
"File '%s' exist\n\t" |
721 |
|
"Size: %.3f MB UID: %d GID: %d Permission: %o\n\t" |
722 |
|
"Monitoring status: %s\n", |
723 |
|
p->name, |
724 |
|
(float) stat_buf.st_size / 1048576, (int)stat_buf.st_uid, |
725 |
|
(int)stat_buf.st_gid, (int)(stat_buf.st_mode & 07777), |
726 |
|
statusnames[p->do_validate]); |
727 |
|
|
728 |
|
} else { |
729 |
|
|
730 |
|
fprintf(out, |
731 |
|
"File '%s' exist\n\t" |
732 |
|
"Size: %.3f MB UID: %d GID: %d Permission: %o\n\t" |
733 |
|
"Monitoring status: %s\n", |
734 |
|
p->name, |
735 |
|
(float) stat_buf.st_size / 1048576, (int)stat_buf.st_uid, |
736 |
|
(int)stat_buf.st_gid, (int)(stat_buf.st_mode & 07777), |
737 |
|
statusnames[p->do_validate]); |
738 |
|
|
739 |
|
} |
740 |
|
} else { |
741 |
|
if( Run.httpdssl ) { |
742 |
|
|
743 |
|
printf_ssl_socket(res->ssl, "File '%s' doesn't exist\n\tMonitoring status: %s\n", |
744 |
|
p->name, statusnames[p->do_validate]); |
745 |
|
|
746 |
|
} else { |
747 |
|
|
748 |
|
fprintf(out, "File '%s' doesn't exist\n\tMonitoring status: %s\n", |
749 |
|
p->name, statusnames[p->do_validate]); |
750 |
|
|
751 |
|
} |
752 |
|
} |
753 |
|
break; |
754 |
|
|
755 |
|
case TASK_DIRECTORY: |
756 |
|
if( (stat(p->path, &stat_buf) == 0) && S_ISDIR(stat_buf.st_mode) ) { |
757 |
|
if( Run.httpdssl ) { |
758 |
|
|
759 |
|
printf_ssl_socket(res->ssl, |
760 |
|
"Directory '%s' exist\n\t" |
761 |
|
"UID: %d GID: %d Permission: %o\n\t" |
762 |
|
"Monitoring status: %s\n", |
763 |
|
p->name, |
764 |
|
(int)stat_buf.st_uid, (int)stat_buf.st_gid, (int)(stat_buf.st_mode & 07777), |
765 |
|
statusnames[p->do_validate]); |
766 |
|
|
767 |
|
} else { |
768 |
|
|
769 |
|
fprintf(out, |
770 |
|
"Directory '%s' exist\n\t" |
771 |
|
"UID: %d GID: %d Permission: %o\n\t" |
772 |
|
"Monitoring status: %s\n", |
773 |
|
p->name, |
774 |
|
(int)stat_buf.st_uid, (int)stat_buf.st_gid, (int)(stat_buf.st_mode & 07777), |
775 |
|
statusnames[p->do_validate]); |
776 |
|
|
777 |
|
} |
778 |
|
} else { |
779 |
|
if( Run.httpdssl ) { |
780 |
|
|
781 |
|
printf_ssl_socket(res->ssl, "Directory '%s' doesn't exist\n\tMonitoring status: %s\n", |
782 |
|
p->name, statusnames[p->do_validate]); |
783 |
|
|
784 |
|
} else { |
785 |
|
|
786 |
|
fprintf(out, "Directory '%s' doesn't exist\n\tMonitoring status: %s\n", |
787 |
|
p->name, statusnames[p->do_validate]); |
788 |
|
|
789 |
|
} |
790 |
|
} |
791 |
|
break; |
792 |
|
|
793 |
|
default: |
794 |
|
break; |
795 |
|
|
796 |
|
} |
797 |
|
|
798 |
|
} |
799 |
|
|
800 |
|
|
801 |
|
static void printPixel(HttpResponse res) { |
802 |
|
|
803 |
|
static int l; |
804 |
|
static unsigned char *pixel= NULL; |
805 |
|
|
806 |
|
if ( ! pixel ) { |
807 |
|
|
808 |
|
pixel= xcalloc(sizeof(unsigned char), strlen(PIXEL_GIF)); |
809 |
|
l= decode_base64(pixel, PIXEL_GIF); |
810 |
|
|
811 |
|
} |
812 |
|
if (l) { |
813 |
|
|
814 |
|
if ( Run.httpdssl ) { |
815 |
|
|
816 |
|
res->is_committed= TRUE; |
817 |
|
|
818 |
|
printf_ssl_socket(res->ssl, "HTTP/1.0 200 OK\r\n"); |
819 |
|
printf_ssl_socket(res->ssl, "Content-length: %d\r\n", l); |
820 |
|
printf_ssl_socket(res->ssl, "Content-Type: image/gif\r\n"); |
821 |
|
printf_ssl_socket(res->ssl, "Connection: close\r\n\r\n"); |
822 |
|
|
823 |
|
send_ssl_socket(res->ssl, pixel, l); |
824 |
|
|
825 |
|
} else { |
826 |
|
|
827 |
|
FILE *out= res->outputstream; |
828 |
|
|
829 |
|
res->is_committed= TRUE; |
830 |
|
|
831 |
|
fprintf(out, "HTTP/1.0 200 OK\r\n"); |
832 |
|
fprintf(out, "Content-length: %d\r\n", l); |
833 |
|
fprintf(out, "Content-Type: image/gif\r\n"); |
834 |
|
fprintf(out, "Connection: close\r\n\r\n"); |
835 |
|
|
836 |
|
fwrite(pixel, sizeof(unsigned char), l, out); |
837 |
|
|
838 |
|
} |
839 |
|
|
840 |
|
} |
841 |
|
|
842 |
|
} |
843 |
|
|
844 |
|
|
845 |
|
static void not_found(HttpRequest req, HttpResponse res) { |
846 |
|
|
847 |
|
send_error(res, SC_NOT_FOUND, |
848 |
|
"The requested URL was not found on this server"); |
849 |
|
|
850 |
|
} |
851 |
|
|
852 |
|
|
853 |
|
static void do_home_process(HttpRequest req, HttpResponse res) { |
854 |
|
|
855 |
|
int on= TRUE; |
856 |
|
int header= TRUE; |
857 |
|
Process_T p; |
858 |
|
|
859 |
|
for (p= processlist; p; p= p->next) { |
860 |
|
|
861 |
|
int isrunning; |
862 |
|
char *uptime; |
863 |
|
|
864 |
|
if(p->task != TASK_PROCESS) continue; |
865 |
|
|
866 |
|
if(header) { |
867 |
|
|
868 |
|
if ( Run.doprocess ) { |
869 |
|
|
870 |
|
out_print(res, |
871 |
|
"<br><p> </p>" |
872 |
|
"<table cellspacing=0 cellpadding=3 border=0 width=\"70%\">" |
873 |
|
"<tr>" |
874 |
|
"<td width=\"20%\"><h3><b>Server</b></h3></td>" |
875 |
|
"<td align=\"left\"><h3><b>Status</b></h3></td>" |
876 |
|
"<td align=\"right\"><h3><b>Uptime</b></h3></td>" |
877 |
|
"<td align=\"right\"><h3><b>CPU</b></h3></td>" |
878 |
|
"<td align=\"right\"><h3><b>Memory</b></h3></td>" |
879 |
|
"</tr>" |
880 |
|
"<tr><td> </td><td> </td></tr>"); |
881 |
|
|
882 |
|
} else { |
883 |
|
|
884 |
|
out_print(res, |
885 |
|
"<table cellspacing=0 cellpadding=3 border=0 width=\"70%\">" |
886 |
|
"<tr>" |
887 |
|
"<td width=\"20%\"><h3><b>Server</b></h3></td>" |
888 |
|
"<td align=\"left\"><h3><b>Status</b></h3></td>" |
889 |
|
"</tr>" |
890 |
|
"<tr><td> </td><td> </td></tr>"); |
891 |
|
|
892 |
|
} |
893 |
|
|
894 |
|
header= FALSE; |
895 |
|
|
896 |
|
} |
897 |
|
|
898 |
|
isrunning= is_process_running(p); |
899 |
|
uptime= get_process_uptime(p->path); |
900 |
|
|
901 |
|
if ( Run.doprocess ) { |
902 |
|
ProcInfo_T pi= p->procinfo; |
903 |
|
if ( isrunning ) { |
904 |
|
out_print(res, |
905 |
|
"<tr %s>" |
906 |
|
"<td width=\"20%\"><a href='/%s'>%s</a></td>" |
907 |
|
"<td align=\"left\">%s</td><td align=\"right\">%s</td>" |
908 |
|
"<td align=\"right\">%.1f%%</td>" |
909 |
|
"<td align=\"right\">%.1f%% [%ldkB]</td></tr>", |
910 |
|
on?"bgcolor=\"#EFEFEF\"":"", |
911 |
|
p->name, p->name, |
912 |
|
p->has_checksum_error? |
913 |
|
"<font color='#ff0000'>Cheksum Error</font>": |
914 |
|
isrunning? |
915 |
|
"<font color=green>running</font>": |
916 |
|
"<font color=red>not running</font>", |
917 |
|
uptime, |
918 |
|
pi->cpu_percent/10.0, |
919 |
|
pi->mem_percent/10.0,pi->mem_kbyte |
920 |
|
); |
921 |
|
} else { |
922 |
|
out_print(res, |
923 |
|
"<tr %s>" |
924 |
|
"<td width=\"20%\"><a href='/%s'>%s</a></td>" |
925 |
|
"<td align=\"left\">%s</td>" |
926 |
|
"<td align=\"right\">-</td>" |
927 |
|
"<td align=\"right\">- </td>" |
928 |
|
"<td align=\"right\">- [-]</td></tr>", |
929 |
|
on?"bgcolor=\"#EFEFEF\"":"", |
930 |
|
p->name, p->name, |
931 |
|
p->has_checksum_error? |
932 |
|
"<font color='#ff0000'>Cheksum Error</font>": |
933 |
|
"<font color=red>not running</font>" |
934 |
|
); |
935 |
|
} |
936 |
|
} else { |
937 |
|
out_print(res, |
938 |
|
"<tr %s>" |
939 |
|
"<td width=\"20%\"><a href='/%s'>%s</a></td>" |
940 |
|
"<td align=\"left\">%s %s</td>" |
941 |
|
"</tr>", |
942 |
|
on?"bgcolor=\"#EFEFEF\"":"", |
943 |
|
p->name, p->name, |
944 |
|
p->has_checksum_error? |
945 |
|
"<font color='#ff0000'>Cheksum Error</font>": |
946 |
|
isrunning? |
947 |
|
"<font color=green>running</font>": |
948 |
|
"<font color=red>not running</font>", |
949 |
|
isrunning?uptime:""); |
950 |
|
} |
951 |
|
|
952 |
|
on= on?FALSE:TRUE; |
953 |
|
free(uptime); |
954 |
|
|
955 |
|
} |
956 |
|
|
957 |
|
out_print(res, "</table>"); |
958 |
|
|
959 |
|
} |
960 |
|
|
961 |
|
|
962 |
|
static void do_home_device(HttpRequest req, HttpResponse res) { |
963 |
|
|
964 |
|
int on= TRUE; |
965 |
|
int header= TRUE; |
966 |
|
Process_T p; |
967 |
|
|
968 |
|
for (p= processlist; p; p= p->next) { |
969 |
|
|
970 |
|
if(p->task != TASK_DEVICE) continue; |
971 |
|
|
972 |
|
if(header) { |
973 |
|
|
974 |
|
out_print(res, |
975 |
|
"<br><p> </p>" |
976 |
|
"<table cellspacing=0 cellpadding=3 border=0 width=\"70%\">" |
977 |
|
"<tr>" |
978 |
|
"<td width=\"20%\"><h3><b>Device</b></h3></td>" |
979 |
|
"<td align=\"left\"><h3><b>Status</b></h3></td>" |
980 |
|
"<td align=\"right\"><h3><b>Space usage</b></h3></td>" |
981 |
|
"<td align=\"right\"><h3><b>Inodes usage</b></h3></td>" |
982 |
|
"</tr>" |
983 |
|
"<tr><td> </td><td> </td></tr>"); |
984 |
|
|
985 |
|
header= FALSE; |
986 |
|
|
987 |
|
} |
988 |
|
|
989 |
|
if(!get_fsusage(p->path, p->devinfo)) { |
990 |
|
|
991 |
|
out_print(res, |
992 |
|
"<tr %s>" |
993 |
|
"<td width=\"20%\"><a href='/%s'>%s</a></td>" |
994 |
|
"<td align=\"left\"><font color=red>not accessible</font></td>" |
995 |
|
"<td align=\"right\">- [-]</td>" |
996 |
|
"<td align=\"right\">- [-]</td>" |
997 |
|
"</tr>", |
998 |
|
on?"bgcolor=\"#EFEFEF\"":"", |
999 |
|
p->name, p->name); |
1000 |
|
|
1001 |
|
} else { |
1002 |
|
|
1003 |
|
if(p->devinfo->f_files > 0) { |
1004 |
|
|
1005 |
|
out_print(res, |
1006 |
|
"<tr %s>" |
1007 |
|
"<td width=\"20%\"><a href='/%s'>%s</a></td>" |
1008 |
|
"<td align=\"left\"><font color=green>accessible</font></td>" |
1009 |
|
"<td align=\"right\">%.1f%% [%.1f MB]</td>" |
1010 |
|
"<td align=\"right\">%.1f%% [%ld objects]</td>" |
1011 |
|
"</tr>", |
1012 |
|
on?"bgcolor=\"#EFEFEF\"":"", |
1013 |
|
p->name, p->name, |
1014 |
|
(float) 100 * (p->devinfo->f_blocks - p->devinfo->f_blocksfree) / p->devinfo->f_blocks, |
1015 |
|
(float) (p->devinfo->f_blocks - p->devinfo->f_blocksfree) / 1048576 * p->devinfo->f_bsize, |
1016 |
|
(float) 100 * (p->devinfo->f_files - p->devinfo->f_filesfree) / p->devinfo->f_files, |
1017 |
|
p->devinfo->f_files - p->devinfo->f_filesfree); |
1018 |
|
|
1019 |
|
} else { |
1020 |
|
|
1021 |
|
out_print(res, |
1022 |
|
"<tr %s>" |
1023 |
|
"<td width=\"20%\"><a href='/%s'>%s</a></td>" |
1024 |
|
"<td align=\"left\"><font color=green>accessible</font></td>" |
1025 |
|
"<td align=\"right\">%.1f%% [%.1f MB]</td>" |
1026 |
|
"<td align=\"right\"><font color=red>not supported by filesystem</font></td>" |
1027 |
|
"</tr>", |
1028 |
|
on?"bgcolor=\"#EFEFEF\"":"", |
1029 |
|
p->name, p->name, |
1030 |
|
(float) 100 * (p->devinfo->f_blocks - p->devinfo->f_blocksfree) / p->devinfo->f_blocks, |
1031 |
|
(float) (p->devinfo->f_blocks - p->devinfo->f_blocksfree) / 1048576 * p->devinfo->f_bsize); |
1032 |
|
|
1033 |
|
} |
1034 |
|
} |
1035 |
|
|
1036 |
|
on= on?FALSE:TRUE; |
1037 |
|
|
1038 |
|
} |
1039 |
|
|
1040 |
|
out_print(res, "</table>"); |
1041 |
|
|
1042 |
|
} |
1043 |
|
|
1044 |
|
|
1045 |
|
static void do_home_file(HttpRequest req, HttpResponse res) { |
1046 |
|
|
1047 |
|
int on= TRUE; |
1048 |
|
int header= TRUE; |
1049 |
|
Process_T p; |
1050 |
|
struct stat stat_buf; |
1051 |
|
|
1052 |
|
for (p= processlist; p; p= p->next) { |
1053 |
|
|
1054 |
|
if(p->task != TASK_FILE) continue; |
1055 |
|
|
1056 |
|
if(header) { |
1057 |
|
|
1058 |
|
out_print(res, |
1059 |
|
"<br><p> </p>" |
1060 |
|
"<table cellspacing=0 cellpadding=3 border=0 width=\"70%\">" |
1061 |
|
"<tr>" |
1062 |
|
"<td width=\"20%\"><h3><b>File</b></h3></td>" |
1063 |
|
"<td align=\"left\"><h3><b>Status</b></h3></td>" |
1064 |
|
"<td align=\"right\"><h3><b>Size</b></h3></td>" |
1065 |
|
"<td align=\"right\"><h3><b>Permission</b></h3></td>" |
1066 |
|
"<td align=\"right\"><h3><b>UID</b></h3></td>" |
1067 |
|
"<td align=\"right\"><h3><b>GID</b></h3></td>" |
1068 |
|
"</tr>" |
1069 |
|
"<tr><td> </td><td> </td></tr>"); |
1070 |
|
|
1071 |
|
header= FALSE; |
1072 |
|
|
1073 |
|
} |
1074 |
|
|
1075 |
|
if( (stat(p->path, &stat_buf) != 0) || !S_ISREG(stat_buf.st_mode) ) { |
1076 |
|
|
1077 |
|
out_print(res, |
1078 |
|
"<tr %s>" |
1079 |
|
"<td width=\"20%\"><a href='/%s'>%s</a></td>" |
1080 |
|
"<td align=\"left\"><font color=red>doesn't exist</font></td>" |
1081 |
|
"<td align=\"right\">-</td>" |
1082 |
|
"<td align=\"right\">-</td>" |
1083 |
|
"<td align=\"right\">-</td>" |
1084 |
|
"<td align=\"right\">-</td>" |
1085 |
|
"</tr>", |
1086 |
|
on?"bgcolor=\"#EFEFEF\"":"", |
1087 |
|
p->name, p->name |
1088 |
|
); |
1089 |
|
|
1090 |
|
} else { |
1091 |
|
|
1092 |
|
out_print(res, |
1093 |
|
"<tr %s>" |
1094 |
|
"<td width=\"20%\"><a href='/%s'>%s</a></td>" |
1095 |
|
"<td align=\"left\"><font color=green>exist</font></td>" |
1096 |
|
"<td align=\"right\">%.3f MB</td>" |
1097 |
|
"<td align=\"right\">%o</td>" |
1098 |
|
"<td align=\"right\">%d</td>" |
1099 |
|
"<td align=\"right\">%d</td>" |
1100 |
|
"</tr>", |
1101 |
|
on?"bgcolor=\"#EFEFEF\"":"", |
1102 |
|
p->name, p->name, |
1103 |
|
(float) stat_buf.st_size / 1048576, |
1104 |
|
stat_buf.st_mode & 07777, |
1105 |
|
stat_buf.st_uid, |
1106 |
|
stat_buf.st_gid |
1107 |
|
); |
1108 |
|
|
1109 |
|
} |
1110 |
|
|
1111 |
|
on= on?FALSE:TRUE; |
1112 |
|
|
1113 |
|
} |
1114 |
|
|
1115 |
|
out_print(res, "</table>"); |
1116 |
|
|
1117 |
|
} |
1118 |
|
|
1119 |
|
|
1120 |
|
static void do_home_directory(HttpRequest req, HttpResponse res) { |
1121 |
|
|
1122 |
|
int on= TRUE; |
1123 |
|
int header= TRUE; |
1124 |
|
Process_T p; |
1125 |
|
struct stat stat_buf; |
1126 |
|
|
1127 |
|
for (p= processlist; p; p= p->next) { |
1128 |
|
|
1129 |
|
if(p->task != TASK_DIRECTORY) continue; |
1130 |
|
|
1131 |
|
if(header) { |
1132 |
|
|
1133 |
|
out_print(res, |
1134 |
|
"<br><p> </p>" |
1135 |
|
"<table cellspacing=0 cellpadding=3 border=0 width=\"70%\">" |
1136 |
|
"<tr>" |
1137 |
|
"<td width=\"20%\"><h3><b>Directory</b></h3></td>" |
1138 |
|
"<td align=\"left\"><h3><b>Status</b></h3></td>" |
1139 |
|
"<td align=\"right\"><h3><b>Permission</b></h3></td>" |
1140 |
|
"<td align=\"right\"><h3><b>UID</b></h3></td>" |
1141 |
|
"<td align=\"right\"><h3><b>GID</b></h3></td>" |
1142 |
|
"</tr>" |
1143 |
|
"<tr><td> </td><td> </td></tr>"); |
1144 |
|
|
1145 |
|
header= FALSE; |
1146 |
|
|
1147 |
|
} |
1148 |
|
|
1149 |
|
if( (stat(p->path, &stat_buf) != 0) || !S_ISDIR(stat_buf.st_mode) ) { |
1150 |
|
|
1151 |
|
out_print(res, |
1152 |
|
"<tr %s>" |
1153 |
|
"<td width=\"20%\"><a href='/%s'>%s</a></td>" |
1154 |
|
"<td align=\"left\"><font color=red>doesn't exist</font></td>" |
1155 |
|
"<td align=\"right\">-</td>" |
1156 |
|
"<td align=\"right\">-</td>" |
1157 |
|
"<td align=\"right\">-</td>" |
1158 |
|
"</tr>", |
1159 |
|
on?"bgcolor=\"#EFEFEF\"":"", |
1160 |
|
p->name, p->name |
1161 |
|
); |
1162 |
|
|
1163 |
|
} else { |
1164 |
|
|
1165 |
|
out_print(res, |
1166 |
|
"<tr %s>" |
1167 |
|
"<td width=\"20%\"><a href='/%s'>%s</a></td>" |
1168 |
|
"<td align=\"left\"><font color=green>exist</font></td>" |
1169 |
|
"<td align=\"right\">%o</td>" |
1170 |
|
"<td align=\"right\">%d</td>" |
1171 |
|
"<td align=\"right\">%d</td>" |
1172 |
|
"</tr>", |
1173 |
|
on?"bgcolor=\"#EFEFEF\"":"", |
1174 |
|
p->name, p->name, |
1175 |
|
stat_buf.st_mode & 07777, |
1176 |
|
stat_buf.st_uid, |
1177 |
|
stat_buf.st_gid |
1178 |
|
); |
1179 |
|
|
1180 |
|
} |
1181 |
|
|
1182 |
|
on= on?FALSE:TRUE; |
1183 |
|
|
1184 |
|
} |
1185 |
|
|
1186 |
|
out_print(res, "</table>"); |
1187 |
|
|
1188 |
|
} |
1189 |
|
|
1190 |
|
|
1191 |
|
static void do_task_device(HttpRequest req, HttpResponse res, Process_T p) { |
1192 |
|
|
1193 |
|
int state= get_fsusage(p->path, p->devinfo); |
1194 |
|
|
1195 |
|
out_print(res, |
1196 |
|
"<p><br><h3>Device status</h3><br>"); |
1197 |
|
out_print(res,"<table cellspacing=0 cellpadding=3 border=1 width=\"90%\">" |
1198 |
|
"<tr><td width=\"30%\"><b>Parameter</b></td><td width=\"70%\"><b>Value</b></td></tr>"); |
1199 |
|
out_print(res, |
1200 |
|
"<tr><td>Name</a></td><td>%s</td></tr>", p->name); |
1201 |
|
out_print(res, |
1202 |
|
"<tr><td>Group</a></td><td><font color='#0000ff'>%s</font></td></tr>", |
1203 |
|
p->group?p->group:"(not defined)"); |
1204 |
|
out_print(res, |
1205 |
|
"<tr><td>Device status</a></td><td>%s</td></tr>", |
1206 |
|
state?"<font color='#00ff00'>Accessible</font>": |
1207 |
|
"<font color='#ff0000'>Not Accessible</font>"); |
1208 |
|
out_print(res, |
1209 |
|
"<tr><td>Path</a></td><td>%s</td></tr>", |
1210 |
|
p->path); |
1211 |
|
out_print(res, |
1212 |
|
"<tr><td>Monitoring mode</a></td><td>%s</td></tr>", |
1213 |
|
modenames[p->mode]); |
1214 |
|
out_print(res, |
1215 |
|
"<tr><td>Monitoring status</a></td><td>%s</td></tr>", |
1216 |
|
statusnames[p->do_validate]); |
1217 |
|
if(p->start) { |
1218 |
|
int i = 0; |
1219 |
|
|
1220 |
|
out_print(res, "<tr><td>Start program</a></td><td>"); |
1221 |
|
while(p->start->arg[i]) |
1222 |
|
out_print(res, "%s ", p->start->arg[i++]); |
1223 |
|
printf("</td></tr>"); |
1224 |
|
} else { |
1225 |
|
out_print(res, |
1226 |
|
"<tr><td>Start program</a></td><td>(not defined)</td></tr>"); |
1227 |
|
} |
1228 |
|
if(p->stop) { |
1229 |
|
int i = 0; |
1230 |
|
|
1231 |
|
out_print(res, "<tr><td>Stop program</a></td><td>"); |
1232 |
|
while(p->stop->arg[i]) |
1233 |
|
out_print(res, "%s ", p->stop->arg[i++]); |
1234 |
|
printf("</td></tr>"); |
1235 |
|
} else { |
1236 |
|
out_print(res, |
1237 |
|
"<tr><td>Stop program</a></td><td>(not defined)</td></tr>"); |
1238 |
|
} |
1239 |
|
{ |
1240 |
|
Dependant_T d; |
1241 |
|
|
1242 |
|
for(d= p->dependantlist; d; d= d->next) { |
1243 |
|
if(d->dependant != NULL) { |
1244 |
|
out_print(res,"<tr><td>Depends on Task </a></td>" |
1245 |
|
"<td> <a href=%s> %s </a></td></tr>", |
1246 |
|
d->dependant, d->dependant); |
1247 |
|
} |
1248 |
|
} |
1249 |
|
} |
1250 |
|
|
1251 |
|
out_print(res, |
1252 |
|
"<tr><td>Check task</a></td><td>Every %d cycle</td></tr>", |
1253 |
|
p->every?p->every:1); |
1254 |
|
out_print(res, |
1255 |
|
"<tr><td>Timeout</a></td><td>Timeout if %d restart within %d cycles" |
1256 |
|
"</td></tr>", p->to_start, p->to_cycle); |
1257 |
|
{ |
1258 |
|
|
1259 |
|
Device_T dl; |
1260 |
|
|
1261 |
|
if(p->devicelist) { |
1262 |
|
|
1263 |
|
for(dl= p->devicelist; dl; dl= dl->next) { |
1264 |
|
|
1265 |
|
if(dl->resource == RESOURCE_INODE) { |
1266 |
|
|
1267 |
|
out_print(res, |
1268 |
|
"<tr><td>Inodes usage limit</a></td><td>if %s %ld %s then %s</td></tr>", |
1269 |
|
operatornames[dl->operator], |
1270 |
|
(dl->limit_absolute > -1)?dl->limit_absolute:dl->limit_percent, |
1271 |
|
(dl->limit_absolute > -1)?"":"%", |
1272 |
|
actionnames[dl->action]); |
1273 |
|
|
1274 |
|
} else if(dl->resource == RESOURCE_SPACE) { |
1275 |
|
|
1276 |
|
out_print(res, |
1277 |
|
"<tr><td>Space usage limit</a></td><td>if %s %ld %s then %s</td></tr>", |
1278 |
|
operatornames[dl->operator], |
1279 |
|
(dl->limit_absolute > -1)?dl->limit_absolute:dl->limit_percent, |
1280 |
|
(dl->limit_absolute > -1)?"blocks":"%", |
1281 |
|
actionnames[dl->action]); |
1282 |
|
|
1283 |
|
} |
1284 |
|
|
1285 |
|
} |
1286 |
|
|
1287 |
|
} |
1288 |
|
|
1289 |
|
if(state) { |
1290 |
|
out_print(res, |
1291 |
|
"<tr><td>Blocks total</a></td><td>%ld [%.1f MB]</td></tr>", |
1292 |
|
p->devinfo->f_blocks, |
1293 |
|
(float) p->devinfo->f_blocks / 1048576 * p->devinfo->f_bsize); |
1294 |
|
out_print(res, |
1295 |
|
"<tr><td>Blocks free for non superuser</a></td><td>%ld [%.1f MB] [%.1f%%]</font></td></tr>", |
1296 |
|
p->devinfo->f_blocksfree, |
1297 |
|
(float) p->devinfo->f_blocksfree / 1048576 * p->devinfo->f_bsize, |
1298 |
|
(float) 100 * p->devinfo->f_blocksfree / p->devinfo->f_blocks); |
1299 |
|
out_print(res, |
1300 |
|
"<tr><td>Blocks free total</a></td><td>%ld [%.1f MB] [%.1f%%]</td></tr>", |
1301 |
|
p->devinfo->f_blocksfreetotal, |
1302 |
|
(float) p->devinfo->f_blocksfreetotal / 1048576 * p->devinfo->f_bsize, |
1303 |
|
(float) 100 * p->devinfo->f_blocksfreetotal / p->devinfo->f_blocks); |
1304 |
|
out_print(res, |
1305 |
|
"<tr><td>Block size</a></td><td>%ld B</td></tr>", |
1306 |
|
p->devinfo->f_bsize); |
1307 |
|
if(p->devinfo->f_files > 0) { |
1308 |
|
out_print(res, |
1309 |
|
"<tr><td>Inodes total</a></td><td>%ld</td></tr>", |
1310 |
|
p->devinfo->f_files); |
1311 |
|
out_print(res, |
1312 |
|
"<tr><td>Inodes free</a></td><td>%ld [%.1f%%]</font></td></tr>", |
1313 |
|
p->devinfo->f_filesfree, |
1314 |
|
(float) 100 * p->devinfo->f_filesfree / p->devinfo->f_files); |
1315 |
|
} |
1316 |
|
} else { |
1317 |
|
out_print(res, |
1318 |
|
"<tr><td>Blocks total</a></td><td>-</td></tr>"); |
1319 |
|
out_print(res, |
1320 |
|
"<tr><td>Blocks free for non superuser</a></td><td>-</font></td></tr>"); |
1321 |
|
out_print(res, |
1322 |
|
"<tr><td>Blocks free total</a></td><td>-</td></tr>"); |
1323 |
|
out_print(res, |
1324 |
|
"<tr><td>Block size</a></td><td>-</td></tr>"); |
1325 |
|
out_print(res, |
1326 |
|
"<tr><td>Inodes total</a></td><td>-</td></tr>"); |
1327 |
|
out_print(res, |
1328 |
|
"<tr><td>Inodes free</a></td><td>-</font></td></tr>"); |
1329 |
|
} |
1330 |
|
} |
1331 |
|
{ |
1332 |
|
Mail_T r; |
1333 |
|
for(r= p->maillist; r; r= r->next) { |
1334 |
|
out_print(res, |
1335 |
|
"<tr bgcolor=\"#EFEFEF\"><td>Alert mail to</a></td><td>%s</td></tr>", |
1336 |
|
r->to?r->to:""); |
1337 |
|
out_print(res, |
1338 |
|
"<tr><td>Alert from</a></td><td>%s</td></tr>", |
1339 |
|
r->from?r->from:"(default)"); |
1340 |
|
out_print(res, |
1341 |
|
"<tr><td>Alert subject</a></td><td>%s</td></tr>", |
1342 |
|
r->subject?r->subject:"(default)"); |
1343 |
|
out_print(res, |
1344 |
|
"<tr><td>Alert message</a></td><td>%s</td></tr>", |
1345 |
|
r->message?r->message:"(default)"); |
1346 |
|
out_print(res, |
1347 |
|
"<tr><td>Alert on timeout</a></td><td>%s</td></tr>", |
1348 |
|
r->alert_on_timeout?"yes":"no"); |
1349 |
|
out_print(res, |
1350 |
|
"<tr><td>Alert on restart</a></td><td>%s</td></tr>", |
1351 |
|
r->alert_on_restart?"yes":"no"); |
1352 |
|
out_print(res, |
1353 |
|
"<tr><td>Alert on checksum</a></td><td>%s</td></tr>", |
1354 |
|
r->alert_on_checksum?"yes":"no"); |
1355 |
|
out_print(res, |
1356 |
|
"<tr><td>Alert on exceeded resource</a></td><td>%s</td></tr>", |
1357 |
|
r->alert_on_resource?"yes":"no"); |
1358 |
|
out_print(res, |
1359 |
|
"<tr><td>Alert on stop</a></td><td>%s</td></tr>", |
1360 |
|
r->alert_on_stop?"yes":"no"); |
1361 |
|
out_print(res, |
1362 |
|
"<tr><td>Alert on timestamp</a></td><td>%s</td></tr>", |
1363 |
|
r->alert_on_timestamp?"yes":"no"); |
1364 |
|
} |
1365 |
|
} |
1366 |
|
out_print(res, "</table>"); |
1367 |
|
out_print(res, "<table cellspacing=16><tr nowrap><td><font size=+1>"); |
1368 |
|
/* Start program */ |
1369 |
|
if(p->start) |
1370 |
|
out_print(res, |
1371 |
|
"<td><form method=GET action=/%s>" |
1372 |
|
"<input type=hidden value='start' name=action>" |
1373 |
|
"<input type=submit value='Start program' style='font-size: 12pt'></font>" |
1374 |
|
"</form></td>", p->name); |
1375 |
|
/* Stop program */ |
1376 |
|
if(p->stop) |
1377 |
|
out_print(res, |
1378 |
|
"<td><form method=GET action=/%s>" |
1379 |
|
"<input type=hidden value='stop' name=action>" |
1380 |
|
"<input type=submit value='Stop program' style='font-size: 12pt'></font>" |
1381 |
|
"</form></td>", p->name); |
1382 |
|
if(p->start && p->stop) |
1383 |
|
out_print(res, |
1384 |
|
"<td><form method=GET action=/%s>" |
1385 |
|
"<input type=hidden value='restart' name=action>" |
1386 |
|
"<input type=submit value='Restart program' style='font-size: 12pt'></font>" |
1387 |
|
"</form></td>", p->name); |
1388 |
|
out_print(res, "</tr></table>"); |
1389 |
|
|
1390 |
|
} |
1391 |
|
|
1392 |
|
|
1393 |
|
static void do_task_directory(HttpRequest req, HttpResponse res, Process_T p) { |
1394 |
|
|
1395 |
|
struct stat stat_buf; |
1396 |
|
int state= ( (stat(p->path, &stat_buf) == 0) && S_ISDIR(stat_buf.st_mode) ); |
1397 |
|
|
1398 |
|
out_print(res, |
1399 |
|
"<p><br><h3>Directory status</h3><br>"); |
1400 |
|
out_print(res,"<table cellspacing=0 cellpadding=3 border=1 width=\"90%\">" |
1401 |
|
"<tr><td width=\"30%\"><b>Parameter</b></td><td width=\"70%\"><b>Value</b></td></tr>"); |
1402 |
|
out_print(res, |
1403 |
|
"<tr><td>Name</a></td><td>%s</td></tr>", p->name); |
1404 |
|
out_print(res, |
1405 |
|
"<tr><td>Group</a></td><td><font color='#0000ff'>%s</font></td></tr>", |
1406 |
|
p->group?p->group:"(not defined)"); |
1407 |
|
out_print(res, |
1408 |
|
"<tr><td>Directory status</a></td><td>%s</td></tr>", |
1409 |
|
state?"<font color='#00ff00'>Exist</font>": |
1410 |
|
"<font color='#ff0000'>Doesn't Exist</font>"); |
1411 |
|
out_print(res, |
1412 |
|
"<tr><td>Path</a></td><td>%s</td></tr>", |
1413 |
|
p->path); |
1414 |
|
out_print(res, |
1415 |
|
"<tr><td>Monitoring mode</a></td><td>%s</td></tr>", |
1416 |
|
modenames[p->mode]); |
1417 |
|
out_print(res, |
1418 |
|
"<tr><td>Monitoring status</a></td><td>%s</td></tr>", |
1419 |
|
statusnames[p->do_validate]); |
1420 |
|
if(p->start) { |
1421 |
|
int i = 0; |
1422 |
|
|
1423 |
|
out_print(res, "<tr><td>Start program</a></td><td>"); |
1424 |
|
while(p->start->arg[i]) |
1425 |
|
out_print(res, "%s ", p->start->arg[i++]); |
1426 |
|
printf("</td></tr>"); |
1427 |
|
} else { |
1428 |
|
out_print(res, |
1429 |
|
"<tr><td>Start program</a></td><td>(not defined)</td></tr>"); |
1430 |
|
} |
1431 |
|
if(p->stop) { |
1432 |
|
int i = 0; |
1433 |
|
|
1434 |
|
out_print(res, "<tr><td>Stop program</a></td><td>"); |
1435 |
|
while(p->stop->arg[i]) |
1436 |
|
out_print(res, "%s ", p->stop->arg[i++]); |
1437 |
|
printf("</td></tr>"); |
1438 |
|
} else { |
1439 |
|
out_print(res, |
1440 |
|
"<tr><td>Stop program</a></td><td>(not defined)</td></tr>"); |
1441 |
|
} |
1442 |
|
{ |
1443 |
|
Dependant_T d; |
1444 |
|
|
1445 |
|
for(d= p->dependantlist; d; d= d->next) { |
1446 |
|
if(d->dependant != NULL) { |
1447 |
|
out_print(res,"<tr><td>Depends on Task </a></td>" |
1448 |
|
"<td> <a href=%s> %s </a></td></tr>", |
1449 |
|
d->dependant, d->dependant); |
1450 |
|
} |
1451 |
|
} |
1452 |
|
} |
1453 |
|
out_print(res, |
1454 |
|
"<tr><td>Check task</a></td><td>Every %d cycle</td></tr>", |
1455 |
|
p->every?p->every:1); |
1456 |
|
out_print(res, |
1457 |
|
"<tr><td>Timeout</a></td><td>Timeout if %d restart within %d cycles" |
1458 |
|
"</td></tr>", p->to_start, p->to_cycle); |
1459 |
|
out_print(res, |
1460 |
|
"<tr><td>UID</a></td><td>%d</td></tr>", |
1461 |
|
stat_buf.st_uid); |
1462 |
|
out_print(res, |
1463 |
|
"<tr><td>GID</a></td><td>%d</td></tr>", |
1464 |
|
stat_buf.st_gid); |
1465 |
|
if(p->perm != -1) |
1466 |
|
out_print(res, "<tr><td>Associated permission</a></td><td>%o</td></tr>", p->perm); |
1467 |
|
out_print(res, |
1468 |
|
"<tr><td>Permission</a></td><td>%o</td></tr>", |
1469 |
|
stat_buf.st_mode & 07777); |
1470 |
|
{ |
1471 |
|
Mail_T r; |
1472 |
|
for(r= p->maillist; r; r= r->next) { |
1473 |
|
out_print(res, |
1474 |
|
"<tr bgcolor=\"#EFEFEF\"><td>Alert mail to</a></td><td>%s</td></tr>", |
1475 |
|
r->to?r->to:""); |
1476 |
|
out_print(res, |
1477 |
|
"<tr><td>Alert from</a></td><td>%s</td></tr>", |
1478 |
|
r->from?r->from:"(default)"); |
1479 |
|
out_print(res, |
1480 |
|
"<tr><td>Alert subject</a></td><td>%s</td></tr>", |
1481 |
|
r->subject?r->subject:"(default)"); |
1482 |
|
out_print(res, |
1483 |
|
"<tr><td>Alert message</a></td><td>%s</td></tr>", |
1484 |
|
r->message?r->message:"(default)"); |
1485 |
|
out_print(res, |
1486 |
|
"<tr><td>Alert on timeout</a></td><td>%s</td></tr>", |
1487 |
|
r->alert_on_timeout?"yes":"no"); |
1488 |
|
out_print(res, |
1489 |
|
"<tr><td>Alert on restart</a></td><td>%s</td></tr>", |
1490 |
|
r->alert_on_restart?"yes":"no"); |
1491 |
|
out_print(res, |
1492 |
|
"<tr><td>Alert on checksum</a></td><td>%s</td></tr>", |
1493 |
|
r->alert_on_checksum?"yes":"no"); |
1494 |
|
out_print(res, |
1495 |
|
"<tr><td>Alert on exceeded resource</a></td><td>%s</td></tr>", |
1496 |
|
r->alert_on_resource?"yes":"no"); |
1497 |
|
out_print(res, |
1498 |
|
"<tr><td>Alert on stop</a></td><td>%s</td></tr>", |
1499 |
|
r->alert_on_stop?"yes":"no"); |
1500 |
|
out_print(res, |
1501 |
|
"<tr><td>Alert on timestamp</a></td><td>%s</td></tr>", |
1502 |
|
r->alert_on_timestamp?"yes":"no"); |
1503 |
|
} |
1504 |
|
} |
1505 |
|
out_print(res, "</table>"); |
1506 |
|
out_print(res, "<table cellspacing=16><tr nowrap><td><font size=+1>"); |
1507 |
|
/* Start program */ |
1508 |
|
if(p->start) |
1509 |
|
out_print(res, |
1510 |
|
"<td><form method=GET action=/%s>" |
1511 |
|
"<input type=hidden value='start' name=action>" |
1512 |
|
"<input type=submit value='Start program' style='font-size: 12pt'></font>" |
1513 |
|
"</form></td>", p->name); |
1514 |
|
/* Stop program */ |
1515 |
|
if(p->stop) |
1516 |
|
out_print(res, |
1517 |
|
"<td><form method=GET action=/%s>" |
1518 |
|
"<input type=hidden value='stop' name=action>" |
1519 |
|
"<input type=submit value='Stop program' style='font-size: 12pt'></font>" |
1520 |
|
"</form></td>", p->name); |
1521 |
|
if(p->start && p->stop) |
1522 |
|
out_print(res, |
1523 |
|
"<td><form method=GET action=/%s>" |
1524 |
|
"<input type=hidden value='restart' name=action>" |
1525 |
|
"<input type=submit value='Restart program' style='font-size: 12pt'></font>" |
1526 |
|
"</form></td>", p->name); |
1527 |
|
out_print(res, "</tr></table>"); |
1528 |
|
|
1529 |
|
} |
1530 |
|
|
1531 |
|
|
1532 |
|
static void do_task_file(HttpRequest req, HttpResponse res, Process_T p) { |
1533 |
|
|
1534 |
|
struct stat stat_buf; |
1535 |
|
int state= ( (stat(p->path, &stat_buf) == 0) && S_ISREG(stat_buf.st_mode) ); |
1536 |
|
|
1537 |
|
out_print(res, |
1538 |
|
"<p><br><h3>File status</h3><br>"); |
1539 |
|
out_print(res,"<table cellspacing=0 cellpadding=3 border=1 width=\"90%\">" |
1540 |
|
"<tr><td width=\"30%\"><b>Parameter</b></td><td width=\"70%\"><b>Value</b></td></tr>"); |
1541 |
|
out_print(res, |
1542 |
|
"<tr><td>Name</a></td><td>%s</td></tr>", p->name); |
1543 |
|
out_print(res, |
1544 |
|
"<tr><td>Group</a></td><td><font color='#0000ff'>%s</font></td></tr>", |
1545 |
|
p->group?p->group:"(not defined)"); |
1546 |
|
out_print(res, |
1547 |
|
"<tr><td>File status</a></td><td>%s</td></tr>", |
1548 |
|
state?"<font color='#00ff00'>Exist</font>": |
1549 |
|
"<font color='#ff0000'>Doesn't Exist</font>"); |
1550 |
|
out_print(res, |
1551 |
|
"<tr><td>Path</a></td><td>%s</td></tr>", |
1552 |
|
p->path); |
1553 |
|
out_print(res, |
1554 |
|
"<tr><td>Monitoring mode</a></td><td>%s</td></tr>", |
1555 |
|
modenames[p->mode]); |
1556 |
|
out_print(res, |
1557 |
|
"<tr><td>Monitoring status</a></td><td>%s</td></tr>", |
1558 |
|
statusnames[p->do_validate]); |
1559 |
|
if(p->start) { |
1560 |
|
int i = 0; |
1561 |
|
|
1562 |
|
out_print(res, "<tr><td>Start program</a></td><td>"); |
1563 |
|
while(p->start->arg[i]) |
1564 |
|
out_print(res, "%s ", p->start->arg[i++]); |
1565 |
|
printf("</td></tr>"); |
1566 |
|
} else { |
1567 |
|
out_print(res, |
1568 |
|
"<tr><td>Start program</a></td><td>(not defined)</td></tr>"); |
1569 |
|
} |
1570 |
|
if(p->stop) { |
1571 |
|
int i = 0; |
1572 |
|
|
1573 |
|
out_print(res, "<tr><td>Stop program</a></td><td>"); |
1574 |
|
while(p->stop->arg[i]) |
1575 |
|
out_print(res, "%s ", p->stop->arg[i++]); |
1576 |
|
printf("</td></tr>"); |
1577 |
|
} else { |
1578 |
|
out_print(res, |
1579 |
|
"<tr><td>Stop program</a></td><td>(not defined)</td></tr>"); |
1580 |
|
} |
1581 |
|
{ |
1582 |
|
struct mychecksum *c; |
1583 |
|
for(c= p->checksumlist; c; c= c->next) |
1584 |
|
out_print(res, "<tr><td>Associated checksum</a></td><td>%s %s</td>" |
1585 |
|
"</tr>", c->md5, c->file); |
1586 |
|
} |
1587 |
|
{ |
1588 |
|
Dependant_T d; |
1589 |
|
|
1590 |
|
for(d= p->dependantlist; d; d= d->next) { |
1591 |
|
if(d->dependant != NULL) { |
1592 |
|
out_print(res,"<tr><td>Depends on Task </a></td>" |
1593 |
|
"<td> <a href=%s> %s </a></td></tr>", |
1594 |
|
d->dependant, d->dependant); |
1595 |
|
} |
1596 |
|
} |
1597 |
|
} |
1598 |
|
{ |
1599 |
|
struct mytimestamp *t; |
1600 |
|
for(t= p->timestamplist; t; t= t->next) |
1601 |
|
out_print(res, |
1602 |
|
"<tr><td>Associated timestamp</a></td>" |
1603 |
|
"<td>If %s %s %d second(s) then %s</td></tr>", |
1604 |
|
t->pathname, operatornames[t->operator], t->time, actionnames[t->action]); |
1605 |
|
} |
1606 |
|
out_print(res, |
1607 |
|
"<tr><td>Check task</a></td><td>Every %d cycle</td></tr>", |
1608 |
|
p->every?p->every:1); |
1609 |
|
out_print(res, |
1610 |
|
"<tr><td>Timeout</a></td><td>Timeout if %d restart within %d cycles" |
1611 |
|
"</td></tr>", p->to_start, p->to_cycle); |
1612 |
|
out_print(res, |
1613 |
|
"<tr><td>Size</a></td><td>%.3f MB</td></tr>", |
1614 |
|
(float) stat_buf.st_size / 1048576); |
1615 |
|
out_print(res, |
1616 |
|
"<tr><td>UID</a></td><td>%d</td></tr>", |
1617 |
|
stat_buf.st_uid); |
1618 |
|
out_print(res, |
1619 |
|
"<tr><td>GID</a></td><td>%d</td></tr>", |
1620 |
|
stat_buf.st_gid); |
1621 |
|
if(p->perm != -1) |
1622 |
|
out_print(res, "<tr><td>Associated permission</a></td><td>%o</td></tr>", p->perm); |
1623 |
|
out_print(res, |
1624 |
|
"<tr><td>Permission</a></td><td>%o</td></tr>", |
1625 |
|
stat_buf.st_mode & 07777); |
1626 |
|
{ |
1627 |
|
Mail_T r; |
1628 |
|
for(r= p->maillist; r; r= r->next) { |
1629 |
|
out_print(res, |
1630 |
|
"<tr bgcolor=\"#EFEFEF\"><td>Alert mail to</a></td><td>%s</td></tr>", |
1631 |
|
r->to?r->to:""); |
1632 |
|
out_print(res, |
1633 |
|
"<tr><td>Alert from</a></td><td>%s</td></tr>", |
1634 |
|
r->from?r->from:"(default)"); |
1635 |
|
out_print(res, |
1636 |
|
"<tr><td>Alert subject</a></td><td>%s</td></tr>", |
1637 |
|
r->subject?r->subject:"(default)"); |
1638 |
|
out_print(res, |
1639 |
|
"<tr><td>Alert message</a></td><td>%s</td></tr>", |
1640 |
|
r->message?r->message:"(default)"); |
1641 |
|
out_print(res, |
1642 |
|
"<tr><td>Alert on timeout</a></td><td>%s</td></tr>", |
1643 |
|
r->alert_on_timeout?"yes":"no"); |
1644 |
|
out_print(res, |
1645 |
|
"<tr><td>Alert on restart</a></td><td>%s</td></tr>", |
1646 |
|
r->alert_on_restart?"yes":"no"); |
1647 |
|
out_print(res, |
1648 |
|
"<tr><td>Alert on checksum</a></td><td>%s</td></tr>", |
1649 |
|
r->alert_on_checksum?"yes":"no"); |
1650 |
|
out_print(res, |
1651 |
|
"<tr><td>Alert on exceeded resource</a></td><td>%s</td></tr>", |
1652 |
|
r->alert_on_resource?"yes":"no"); |
1653 |
|
out_print(res, |
1654 |
|
"<tr><td>Alert on stop</a></td><td>%s</td></tr>", |
1655 |
|
r->alert_on_stop?"yes":"no"); |
1656 |
|
out_print(res, |
1657 |
|
"<tr><td>Alert on timestamp</a></td><td>%s</td></tr>", |
1658 |
|
r->alert_on_timestamp?"yes":"no"); |
1659 |
|
} |
1660 |
|
} |
1661 |
|
out_print(res, "</table>"); |
1662 |
|
out_print(res, "<table cellspacing=16><tr nowrap><td><font size=+1>"); |
1663 |
|
/* Start program */ |
1664 |
|
if(p->start) |
1665 |
|
out_print(res, |
1666 |
|
"<td><form method=GET action=/%s>" |
1667 |
|
"<input type=hidden value='start' name=action>" |
1668 |
|
"<input type=submit value='Start program' style='font-size: 12pt'></font>" |
1669 |
|
"</form></td>", p->name); |
1670 |
|
/* Stop program */ |
1671 |
|
if(p->stop) |
1672 |
|
out_print(res, |
1673 |
|
"<td><form method=GET action=/%s>" |
1674 |
|
"<input type=hidden value='stop' name=action>" |
1675 |
|
"<input type=submit value='Stop program' style='font-size: 12pt'></font>" |
1676 |
|
"</form></td>", p->name); |
1677 |
|
if(p->start && p->stop) |
1678 |
|
out_print(res, |
1679 |
|
"<td><form method=GET action=/%s>" |
1680 |
|
"<input type=hidden value='restart' name=action>" |
1681 |
|
"<input type=submit value='Restart program' style='font-size: 12pt'></font>" |
1682 |
|
"</form></td>", p->name); |
1683 |
|
out_print(res, "</tr></table>"); |
1684 |
|
|
1685 |
|
} |
1686 |
|
|
1687 |
|
|
1688 |
|
static void do_task_process(HttpRequest req, HttpResponse res, Process_T p) { |
1689 |
|
|
1690 |
|
int run= is_process_running(p); |
1691 |
|
|
1692 |
out_print(res, |
out_print(res, |
1693 |
"<p><br><h3>Process status</h3><br>"); |
"<p><br><h3>Process status</h3><br>"); |
1694 |
out_print(res,"<table cellspacing=0 cellpadding=3 border=1 width=\"90%\">" |
out_print(res,"<table cellspacing=0 cellpadding=3 border=1 width=\"90%\">" |
1708 |
"<font color='#ff0000'><b>Checksum error!</b></font>":""); |
"<font color='#ff0000'><b>Checksum error!</b></font>":""); |
1709 |
out_print(res, |
out_print(res, |
1710 |
"<tr><td>Pid file</a></td><td>%s</td></tr>", |
"<tr><td>Pid file</a></td><td>%s</td></tr>", |
1711 |
p->pidfile); |
p->path); |
1712 |
out_print(res, |
out_print(res, |
1713 |
"<tr><td>Monitoring mode</a></td><td>%s</td></tr>", |
"<tr><td>Monitoring mode</a></td><td>%s</td></tr>", |
1714 |
modenames[p->mode]); |
modenames[p->mode]); |
1715 |
out_print(res, |
out_print(res, |
1716 |
"<tr><td>Monitoring status</a></td><td>%s</td></tr>", |
"<tr><td>Monitoring status</a></td><td>%s</td></tr>", |
1717 |
statusnames[p->do_validate]); |
statusnames[p->do_validate]); |
1718 |
out_print(res, |
if(p->start) { |
1719 |
"<tr><td>Start program</a></td><td>%s</td></tr>", |
int i = 0; |
1720 |
p->start?p->start->arg[0]:"(not defined)"); |
|
1721 |
out_print(res, |
out_print(res, "<tr><td>Start program</a></td><td>"); |
1722 |
"<tr><td>Stop program</a></td><td>%s</td></tr>", |
while(p->start->arg[i]) |
1723 |
p->stop?p->stop->arg[0]:"(not defined)"); |
out_print(res, "%s ", p->start->arg[i++]); |
1724 |
|
printf("</td></tr>"); |
1725 |
|
} else { |
1726 |
|
out_print(res, |
1727 |
|
"<tr><td>Start program</a></td><td>(not defined)</td></tr>"); |
1728 |
|
} |
1729 |
|
if(p->stop) { |
1730 |
|
int i = 0; |
1731 |
|
|
1732 |
|
out_print(res, "<tr><td>Stop program</a></td><td>"); |
1733 |
|
while(p->stop->arg[i]) |
1734 |
|
out_print(res, "%s ", p->stop->arg[i++]); |
1735 |
|
printf("</td></tr>"); |
1736 |
|
} else { |
1737 |
|
out_print(res, |
1738 |
|
"<tr><td>Stop program</a></td><td>(not defined)</td></tr>"); |
1739 |
|
} |
1740 |
{ |
{ |
1741 |
struct mychecksum *c; |
struct mychecksum *c; |
1742 |
for(c= p->checksumlist; c; c= c->next) |
for(c= p->checksumlist; c; c= c->next) |
1748 |
|
|
1749 |
for(d= p->dependantlist; d; d= d->next) { |
for(d= p->dependantlist; d; d= d->next) { |
1750 |
if(d->dependant != NULL) { |
if(d->dependant != NULL) { |
1751 |
out_print(res,"<tr><td>Depends on Process </a></td>" |
out_print(res,"<tr><td>Depends on Task </a></td>" |
1752 |
"<td> <a href=%s> %s </a></td></tr>", |
"<td> <a href=%s> %s </a></td></tr>", |
1753 |
d->dependant, d->dependant); |
d->dependant, d->dependant); |
1754 |
} |
} |
1764 |
"<tr><td>Memory usage</a></td><td>%.1f%% [%ldkB]</td></tr>", |
"<tr><td>Memory usage</a></td><td>%.1f%% [%ldkB]</td></tr>", |
1765 |
pi->mem_percent/10.0,pi->mem_kbyte); |
pi->mem_percent/10.0,pi->mem_kbyte); |
1766 |
out_print(res, |
out_print(res, |
1767 |
"<tr><td>Children</a></td><td>%d</td></tr>", |
"<tr><td>Children</a></td><td>%d</td></tr>", |
1768 |
pi->children); |
pi->children); |
1769 |
out_print(res, |
out_print(res, |
1770 |
"<tr><td>Total memory usage (incl. children) </a></td><td>%.1f%% [%ldkB]</td></tr>", |
"<tr><td>Total memory usage (incl. children) </a></td><td>%.1f%% [%ldkB]</td></tr>", |
1771 |
pi->total_mem_percent/10.0,pi->total_mem_kbyte); |
pi->total_mem_percent/10.0,pi->total_mem_kbyte); |
1772 |
} |
} |
1773 |
{ |
{ |
1774 |
Port_T n; |
Port_T n; |
1877 |
actionnames[q->action]); |
actionnames[q->action]); |
1878 |
break; |
break; |
1879 |
|
|
1880 |
case RESOURCE_ID_CHILDREN: |
case RESOURCE_ID_CHILDREN: |
1881 |
out_print(res,"<tr><td>Children</a></td>" |
out_print(res,"<tr><td>Children</a></td>" |
1882 |
"<td>If %s %d for %d cycle(s) then %s</td></tr>", |
"<td>If %s %d for %d cycle(s) then %s</td></tr>", |
1883 |
operatornames[q->operator], |
operatornames[q->operator], |
1884 |
q->limit, q->max_cycle, |
q->limit, q->max_cycle, |
1885 |
actionnames[q->action]); |
actionnames[q->action]); |
1886 |
break; |
break; |
1887 |
|
|
1888 |
case RESOURCE_ID_TOTAL_MEM_KBYTE: |
case RESOURCE_ID_TOTAL_MEM_KBYTE: |
1889 |
out_print(res,"<tr><td>Memory amount limit (incl. children)</a></td>" |
out_print(res,"<tr><td>Memory amount limit (incl. children)</a></td>" |
1890 |
"<td>If %s %d for %d cycle(s) then %s</td></tr>", |
"<td>If %s %d for %d cycle(s) then %s</td></tr>", |
1891 |
operatornames[q->operator], |
operatornames[q->operator], |
1892 |
q->limit, q->max_cycle, |
q->limit, q->max_cycle, |
1893 |
actionnames[q->action]); |
actionnames[q->action]); |
1894 |
break; |
break; |
1895 |
|
|
1896 |
case RESOURCE_ID_TOTAL_MEM_PERCENT: |
case RESOURCE_ID_TOTAL_MEM_PERCENT: |
1897 |
out_print(res,"<tr><td>Memory usage limit (incl. children)</a></td>" |
out_print(res,"<tr><td>Memory usage limit (incl. children)</a></td>" |
1898 |
"<td>If %s %.1f%% for %d cycle(s) then %s</td></tr>", |
"<td>If %s %.1f%% for %d cycle(s) then %s</td></tr>", |
1899 |
operatornames[q->operator], |
operatornames[q->operator], |
1900 |
q->limit/10.0, q->max_cycle, |
q->limit/10.0, q->max_cycle, |
1901 |
actionnames[q->action]); |
actionnames[q->action]); |
1902 |
break; |
break; |
1903 |
|
|
1904 |
} |
} |
1905 |
} |
} |
1906 |
} |
} |
1907 |
out_print(res, |
out_print(res, |
1908 |
"<tr><td>Check process</a></td><td>Every %d cycle</td></tr>", |
"<tr><td>Check task</a></td><td>Every %d cycle</td></tr>", |
1909 |
p->every?p->every:1); |
p->every?p->every:1); |
1910 |
out_print(res, |
out_print(res, |
1911 |
"<tr><td>Timeout</a></td><td>Timeout if %d restart within %d cycles" |
"<tr><td>Timeout</a></td><td>Timeout if %d restart within %d cycles" |
1953 |
"<td><form method=GET action=/%s>" |
"<td><form method=GET action=/%s>" |
1954 |
"<input type=hidden value='start' name=action>" |
"<input type=hidden value='start' name=action>" |
1955 |
"<input type=submit value='Start program' style='font-size: 12pt'></font>" |
"<input type=submit value='Start program' style='font-size: 12pt'></font>" |
1956 |
"</form></td>", name); |
"</form></td>", p->name); |
1957 |
/* Stop program */ |
/* Stop program */ |
1958 |
if(p->stop) |
if(p->stop) |
1959 |
out_print(res, |
out_print(res, |
1960 |
"<td><form method=GET action=/%s>" |
"<td><form method=GET action=/%s>" |
1961 |
"<input type=hidden value='stop' name=action>" |
"<input type=hidden value='stop' name=action>" |
1962 |
"<input type=submit value='Stop program' style='font-size: 12pt'></font>" |
"<input type=submit value='Stop program' style='font-size: 12pt'></font>" |
1963 |
"</form></td>", name); |
"</form></td>", p->name); |
1964 |
if(p->start && p->stop) |
if(p->start && p->stop) |
1965 |
out_print(res, |
out_print(res, |
1966 |
"<td><form method=GET action=/%s>" |
"<td><form method=GET action=/%s>" |
1967 |
"<input type=hidden value='restart' name=action>" |
"<input type=hidden value='restart' name=action>" |
1968 |
"<input type=submit value='Restart program' style='font-size: 12pt'></font>" |
"<input type=submit value='Restart program' style='font-size: 12pt'></font>" |
1969 |
"</form></td>", name); |
"</form></td>", p->name); |
1970 |
out_print(res, "</tr></table>"); |
out_print(res, "</tr></table>"); |
1971 |
|
|
|
FOOT |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
static void print_status(Process_T p, HttpResponse res) { |
|
|
|
|
|
pid_t pid= -1; |
|
|
FILE *out= res->outputstream; |
|
|
|
|
|
res->is_committed= TRUE; |
|
|
|
|
|
if((pid= is_process_running(p))) { |
|
|
|
|
|
char *uptime= get_process_uptime(p->pidfile); |
|
|
char buf[STRLEN]; |
|
|
ProcInfo_T pi= p->procinfo; |
|
|
|
|
|
if ( Run.doprocess ) { |
|
|
|
|
|
sprintf(buf, |
|
|
"Process '%s' is running with pid [%d]\n\tUptime: %s " |
|
|
"CPU: %.1f%% Memory w/o children: %.1f%% [%ldkB]\n" |
|
|
"\tChildren: %i Memory w/ children: %.1f%% [%ldkB]\n" |
|
|
"\tMonitoring status: %s\n", |
|
|
p->name, (int)pid, uptime, pi->cpu_percent/10.0, |
|
|
pi->mem_percent/10.0,pi->mem_kbyte, |
|
|
pi->children,pi->total_mem_percent/10.0,pi->total_mem_kbyte, |
|
|
statusnames[p->do_validate]); |
|
|
|
|
|
} else { |
|
|
|
|
|
sprintf(buf, |
|
|
"Process '%s' is running with pid [%d]\n\tUptime: %s " |
|
|
"\tMonitoring status: %s\n", |
|
|
p->name, (int)pid, uptime,statusnames[p->do_validate]); |
|
|
|
|
|
} |
|
|
|
|
|
if( Run.httpdssl ) { |
|
|
|
|
|
printf_ssl_socket(res->ssl, "%s", buf); |
|
|
|
|
|
} else { |
|
|
|
|
|
fprintf(out, "%s", buf); |
|
|
|
|
|
} |
|
|
|
|
|
free(uptime); |
|
|
|
|
|
} else { |
|
|
|
|
|
if( Run.httpdssl ) { |
|
|
|
|
|
printf_ssl_socket(res->ssl, "Process '%s' is not running\n", p->name); |
|
|
|
|
|
} else { |
|
|
|
|
|
fprintf(out, "Process '%s' is not running\n", p->name); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
static void printPixel(HttpResponse res) { |
|
|
|
|
|
static int l; |
|
|
static unsigned char *pixel= NULL; |
|
|
|
|
|
if ( ! pixel ) { |
|
|
|
|
|
pixel= xcalloc(sizeof(unsigned char), strlen(PIXEL_GIF)); |
|
|
l= decode_base64(pixel, PIXEL_GIF); |
|
|
|
|
|
} |
|
|
if (l) { |
|
|
|
|
|
if ( Run.httpdssl ) { |
|
|
|
|
|
res->is_committed= TRUE; |
|
|
|
|
|
printf_ssl_socket(res->ssl, "HTTP/1.0 200 OK\r\n"); |
|
|
printf_ssl_socket(res->ssl, "Content-length: %d\r\n", l); |
|
|
printf_ssl_socket(res->ssl, "Content-Type: image/gif\r\n"); |
|
|
printf_ssl_socket(res->ssl, "Connection: close\r\n\r\n"); |
|
|
|
|
|
send_ssl_socket(res->ssl, pixel, l); |
|
|
|
|
|
} else { |
|
|
|
|
|
FILE *out= res->outputstream; |
|
|
|
|
|
res->is_committed= TRUE; |
|
|
|
|
|
fprintf(out, "HTTP/1.0 200 OK\r\n"); |
|
|
fprintf(out, "Content-length: %d\r\n", l); |
|
|
fprintf(out, "Content-Type: image/gif\r\n"); |
|
|
fprintf(out, "Connection: close\r\n\r\n"); |
|
|
|
|
|
fwrite(pixel, sizeof(unsigned char), l, out); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
static void not_found(HttpRequest req, HttpResponse res) { |
|
|
|
|
|
send_error(res, SC_NOT_FOUND, |
|
|
"The requested URL was not found on this server"); |
|
|
|
|
1972 |
} |
} |
1973 |
|
|