Ad Widget

Collapse

Zabbix Return SQL Table Value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ningrus
    Junior Member
    • Feb 2014
    • 4

    #1

    Zabbix Return SQL Table Value

    Hello friends, I am facing a problem that desperately need help!
    I have a table in a database for monitoring database is SQL Server where it is populated by a job script.

    To help me in this case, I researched a lot and got to ride through a script to grab these values ​​and load into the zabbix.

    Now the golden question, in a certain column named status, I need it to be read to search for a value that is> than 0, if there he would present me the database name and the value (in this theory), but when I run into the zabbix, first time he tells me he can not because the item key is repeated, as I did to remedy the problem changed the name of the item key. But it is giving problems and does not support the value.

    please help me?

    I'm entering the didactic script and if possible in order that they may understand my doubts!
    Attached Files
  • tsalle
    Member
    Zabbix Certified Specialist
    • Oct 2012
    • 79

    #2
    Hi,

    Maybe you can use the UserParameter in a user agent config file, to grab the last value of a particular item.

    for example :
    Code:
    UserParameter=get.value[*],script_to_extract_sql_value $1
    Then create a Zabbix item with a key "get.value[my_field]" to fetch the latest value of this field.
    After that you just have to create trigger when the value is > threshold :
    Code:
    {myhost:get.value[my_field].last(0)}>threshold

    Comment

    • Ningrus
      Junior Member
      • Feb 2014
      • 4

      #3
      In case I am using this script to auto discovery, when I do this it makes the name of the query (database) and key (database + err + status (due to the key item can not be repeated), but as the table no return value because I like that it returns the value of a column line. still do not know how to do this.
      The line below shows the field within my script that will be sending the information of name and key for zabbix, but wanted to have a key field value returned for the zabbix can understand;

      OutputLine = "{" "} {# DATABASE" "" "" & goAdoRS ("mon_Database") & "" "" "# {STATUS}" "" "" & goAdoRS ("mon_status") & "" "}"

      I'm trying to make a dynamic independent monitoring of the amount of banks that the server has, therefore this whole problem.
      Once you get done, put in the script and communicated a tutorial for use.

      Comment

      • steveboyson
        Senior Member
        • Jul 2013
        • 582

        #4
        From 2.2.x, the "lastvalue" (which is the newest stored value) field is no longer in the "items" table. It is stored in the history[_uint, _text, _str, _log] tables instead.

        You have to:
        - find the itemid, value_type of your item
        - determine, which history* table is holding the latest value, by checking "value_type" field
        Code:
               0 => 'history',
                1 => 'history_str',
                2 => 'history_log',
                3 => 'history_uint',
                4 => 'history_text',
        - "select value from [history_table_determined_before] where itemid = <your-itemid> order by clock DESC limit 1"

        This will give you the latest acquired value for your item.

        I learned it the hard way the last days since all my 2.0-scripts need to get some rework.

        Comment

        Working...