Uploaded image for project: 'ZABBIX BUGS AND ISSUES'
  1. ZABBIX BUGS AND ISSUES
  2. ZBX-3903

Issue encounter when Trying to create my own zabbix Active agent with java Socket in order to get Log Error from Log4j to Zabbix Server the time they appear

XMLWordPrintable

    • Icon: Problem report Problem report
    • Resolution: Won't fix
    • Icon: Trivial Trivial
    • None
    • 1.8.5
    • Agent (G)
    • None
    • J2EE Applications running on Weblogic Server

      Hi,
      I am actually writing a zabbix appender for Log4j to get the logs at the time they are generated by Log4j to Zabbix Server. In other words, I am doing a kind of Active Agents in Java that is called by log4j when an error is present. So, I would like to have some details about the protocol used between the agent and zabbix server in an orderly manner. I read the source code of the agent in C , I saw that you open a tcp connection , then the agent send the data to the server, and the agent reads the Zabbix response, then closes the connection. I tried to do the same, but I always get OK as a response for whichever the message and nothing else as it would do with a real zabbix agent. I used JSON Format defined in a constant string with some keys and hostname(Active agents) I already defined in the Zabbix PHP Frontend. Still I cannot get it worked. Please, Help me because there is no detail about the protocol you used in the documentation. Attached is my java code, you may review it so that you can tell me what misses to make it work. And I planned to make it open source because Nagios already had a log4j appender, but , me , I'd like to use Zabbix instead of Nagios.

      import java.net.Socket;
      import java.net.InetAddress;
      import java.io.InputStreamReader;
      import java.io.PrintWriter;
      import java.io.BufferedReader;
      public class ZabbixSocket {

      /**

      • @param args
        */
        public static void main(String[] args) throws Exception {
        // TODO Auto-generated method stub
        //System.out.println("Je suis la");
        Socket sock=new Socket("192.168.61.11",10051); //Connect to zabbix Server
        String data=null;
        BufferedReader ServerStream=null;
        PrintWriter ClientStream=null;
        //String header=" {\"request\":\"active checks\",\"host\":\"tech-alsb2_test\"}

        ";

      String header="ZBXD3

      {\n\t" + "\"request\":\"active checks\",\n\t" + "\"host\":\"doug_pc\"}

      ";
      //Active check header to get the list of keys from server

      String zabbix_payload="ZBXD8{\"request\":\"agent data\",\"data\":[

      {\"host\":\"doug_pc\",\"key\":\"proc.num\",\"value\":\"9\",\"clock\":1308573045}

      ],\"clock\":1308573046}";

      ServerStream = new BufferedReader(new InputStreamReader(sock.getInputStream()));

      //Send active check header to get the list of keys from server
      ClientStream = new PrintWriter(sock.getOutputStream(),true);
      System.out.println("Zabbix Agent Request keys");
      System.out.println(header+"\n");

      ClientStream.println(header);

      //Read the data returned by the server and print it to the screen :
      while( ( data= ServerStream.readLine())!=null)
      System.out.println(data); //It always return ok, instead of the list of keys

      sock.close();

      System.out.println("Connection closed ");

      //New Connection
      sock=new Socket("192.168.61.11",10051); //Re-open the connection to Zabbix Server

      ServerStream = new BufferedReader(new InputStreamReader(sock.getInputStream()));

      ClientStream = new PrintWriter(sock.getOutputStream(),true);

      //We send the the Value we want to the Zabbix Server so that it can be showed on the PHP Frontend. But it never updates it!!
      System.out.println("Zabbix Payload sent \n: "zabbix_payload"\n ");
      ClientStream.println(zabbix_payload);

      while( ( data= ServerStream.readLine())!=null) //We read the Response returned by the Server
      System.out.println(data); //It always returned OK and nothing else

      sock.close(); //Close the socket
      System.out.println("Connection \"closed\" ");

      }

      }

            Unassigned Unassigned
            douggynix James Douglass Lefruit
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: