Ad Widget

Collapse

Custom scripts - Increasing limit beyond 255 chars?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tiarnaigh
    Junior Member
    • Sep 2013
    • 27

    #1

    Custom scripts - Increasing limit beyond 255 chars?

    Hi guys.
    Custom scripts are something I use a lot in Zabbix UI (i.e. Administration/Scripts) to running remote command etc. on various servers. Currently, there appears to be a hard set limit of 255 characters per script/command, and I was hoping someone could advise on how I can increase this?

    I have tried modifying the Zabbix database, "scripts" table as per below and changing the default "command" column from a "character varying(255)" type to say a "character varying(500)" type, but this doesn't seem to have made any difference.

    Is there an easy way to do this?

    Thanks in advance,
    M

    zabbix=# \d scripts;
    Table "public.scripts"
    Column | Type | Modifiers
    --------------+------------------------+----------------------------------------
    scriptid | bigint | not null
    name | character varying(255) | not null default ''::character varying
    command | character varying(255) | not null default ''::character varying
    host_access | integer | not null default 2
    usrgrpid | bigint |
    groupid | bigint |
    description | text | not null default ''::text
    confirmation | character varying(255) | not null default ''::character varying
    type | integer | not null default 0
    execute_on | integer | not null default 1
    Indexes:
    "scripts_pkey" PRIMARY KEY, btree (scriptid)
    "scripts_3" UNIQUE, btree (name)
    "scripts_1" btree (usrgrpid)
    "scripts_2" btree (groupid)
    Foreign-key constraints:
    "c_scripts_1" FOREIGN KEY (usrgrpid) REFERENCES usrgrp(usrgrpid)
    "c_scripts_2" FOREIGN KEY (groupid) REFERENCES groups(groupid)
    Referenced by:
    TABLE "opcommand" CONSTRAINT "c_opcommand_2" FOREIGN KEY (scriptid) REFERENCES scripts(scriptid)

    zabbix=# ALTER TABLE scripts ALTER COLUMN command TYPE character varying(500);
    ALTER TABLE


    zabbix=# \d scripts;
    Table "public.scripts"
    Column | Type | Modifiers
    --------------+------------------------+----------------------------------------
    scriptid | bigint | not null
    name | character varying(255) | not null default ''::character varying
    command | character varying(500) | not null default ''::character varying
    host_access | integer | not null default 2
    usrgrpid | bigint |
    groupid | bigint |
    description | text | not null default ''::text
    confirmation | character varying(255) | not null default ''::character varying
    type | integer | not null default 0
    execute_on | integer | not null default 1
    Indexes:
    "scripts_pkey" PRIMARY KEY, btree (scriptid)
    "scripts_3" UNIQUE, btree (name)
    "scripts_1" btree (usrgrpid)
    "scripts_2" btree (groupid)
    Foreign-key constraints:
    "c_scripts_1" FOREIGN KEY (usrgrpid) REFERENCES usrgrp(usrgrpid)
    "c_scripts_2" FOREIGN KEY (groupid) REFERENCES groups(groupid)
    Referenced by:
    TABLE "opcommand" CONSTRAINT "c_opcommand_2" FOREIGN KEY (scriptid) REFERENCES scripts(scriptid)
  • tiarnaigh
    Junior Member
    • Sep 2013
    • 27

    #2
    I actually found this since, thanks to a related old post to do with triggers & upper limits (https://support.zabbix.com/browse/ZBX-4302). Solution was pretty simple in the end:

    Updated DB as follows to increase the "command" column from 255 to 1024 (Can be increased to more I guess) as follows:

    zabbix=# ALTER TABLE scripts ALTER COLUMN command TYPE character varying(1024);
    ALTER TABLE

    Once I did this, I then updated /var/www/html/zabbix/include/schema.inc.php for this specific field to correspond to new value as per below:


    Code:
       1578         'scripts' => array(
       1579                 'key' => 'scriptid',
       1580                 'fields' => array(
       1581                         'scriptid' => array(
       1582                                 'null' => false,
       1583                                 'type' => DB::FIELD_TYPE_ID,
       1584                                 'length' => 20,
       1585                         ),
       1586                         'name' => array(
       1587                                 'null' => false,
       1588                                 'type' => DB::FIELD_TYPE_CHAR,
       1589                                 'length' => 255,
       1590                                 'default' => '',
       1591                         ),
       1592                         'command' => array(
       1593                                 'null' => false,
       1594                                 'type' => DB::FIELD_TYPE_CHAR,
       [B]1595                                 'length' => 1024,[/B]
       1596                                 'default' => '',
       1597                         ),
       1598                         'host_access' => array(
       1599                                 'null' => false,
       1600                                 'type' => DB::FIELD_TYPE_INT,
       1601                                 'length' => 10,
       1602                                 'default' => '2',
       1603                         ),

    Comment

    • NOB
      Senior Member
      Zabbix Certified Specialist
      • Mar 2007
      • 469

      #3
      Good luck

      This might be just one part of the story and in the end might break your server and/or agent !

      Think about it:

      What if the agent executing this command has a limit of 255 characters but does
      not check if a longer command arrives and executes this ?
      It might work once, it might work twice, but overwriting some data at
      the end of the memory (stack) might be a problem you'll notice later.

      A similar thing is true for the server.
      If it just reads the whole command in the DB but has a limit of 255 characters
      the same memory corruption might happen.

      You should at least check those sources and fix them if required, too !

      Kind regards
      Norbert.

      Comment

      • tiarnaigh
        Junior Member
        • Sep 2013
        • 27

        #4
        Fair point NOB.
        Wasn't the allowed size of the remote agent execution command increased from Zabbix v2.x onwards though to 2048 bytes, or something along those lines? I ran a few tests like the below for instance using the zabbix_get & system.run commands, and I seem to be good up to over the 500 character mark:

        /sys_apps_01/zabbix/bin/zabbix_get -s 10.157.192.127 -k system.run['echo "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa a" > /tmp/test','wait'];


        I didn't make any changes on the agent side (Guessing I'd need to hack the c code for this and recompile etc.), but merely on the servers side, which was just an update to the table and a change to the php config file. PHp shouldn't enforce any hard set memory limits I'm guessing....

        Comment

        Working...