Problems with adding my own command

aragonx at dcsnow.com aragonx at dcsnow.com
Tue Nov 27 22:15:00 CET 2007


Hello all,

I am trying to add a command.  I would like to have a link on the
hostgroup page that would allow me to run a bash script on each host in
that hostgroup.  Passing the script the hostname as a command line
parameter.

Everything seems to work fine.  I have a link on the hostgroup page that
says what I want.  When I click on it, I get a new page that says just
about what I want.  When I click on commit however, I get:  "An error
occurred while attempting to commit your command for processing."

I haven't done much C development so I don't have a real good idea as to
what I should be doing.  I have a feeling the problem is with the function
I have added in commands.c.  Here is what I have done:

I have modified the following files:

base/commands.c
cgi/cmd.c
include/common.h
include/nagios.h.in
include/nagios.h

In commands.c under function void check_for_external_commands(void)
                else if(!strcmp(command_id,"RUN_CMD_ON_HOSTGROUP"))
                        command_type=CMD_RUN_CMD_ON_HOSTGROUP;

In commands.c under function void process_external_command(int cmd, time_t
entry_time, char *args)
        case CMD_RUN_CMD_ON_HOSTGROUP:
                process_hostgroup_command(cmd,entry_time,args);
                break;

In commands.c under function process_hostgroup_command(int cmd, time_t
entry_time, char *args)
                case CMD_RUN_CMD_ON_HOSTGROUP:
                        run_cmd_on_hostgroup(temp_host);
                        break;

In commands.c added function run_cmd_on_hostgroup(host *hst)
   char extcmd[200];
#ifdef DEBUG0
        printf("run_cmd_on_hostgroup() start\n");
#endif

        /* Run the script. */
        strcpy(extcmd, "/usr/local/nagios/bin/hostgroup.bash ");
        strcat(extcmd, hst->name);
        system(extcmd);

#ifdef DEBUG0
        printf("run_cmd_on_hostgroup() with command as %s end\n", extcmd);
#endif

        return;
        }

in cmd.c under function request_command_data(int cmd)
        case CMD_RUN_CMD_ON_HOSTGROUP:
                printf("Distribution script run on all hosts in a
particular hostgroup");
                break;

        case CMD_RUN_CMD_ON_HOSTGROUP:
                printf("<tr><td CLASS='optBoxRequiredItem'>Hostgroup
Name:</td><td><b>");
                printf("<INPUT TYPE='TEXT' NAME='hostgroup'
VALUE='%s'>",hostgroup_name);
                printf("</b></td></tr>\n");
                if(cmd==CMD_RUN_CMD_ON_HOSTGROUP){
                        printf("<INPUT TYPE='checkbox' NAME='ahas'>");
                        printf("</b></td></tr>\n");
                        }
                break;
        case CMD_RUN_CMD_ON_HOSTGROUP:

                /* see if the user is authorized to issue a command... */
                temp_hostgroup=find_hostgroup(hostgroup_name);
                if(is_authorized_for_hostgroup(temp_hostgroup,&current_authdata)==TRUE)
                        authorized=TRUE;

                break;
In cmd.c under function show_command_help(cmd)
        case CMD_RUN_CMD_ON_HOSTGROUP:
                printf("This command is used to copy files to all the
hosts in the host group.\n");
                break;

in common.h
#define CMD_RUN_CMD_ON_HOSTGROUP                        144

In nagios.h
void run_cmd_on_hostgroup(host *);                      /* Distributes
files to all hosts in a host group */

As always, any help would be appreciated.




-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list