1 Server-proxy 数据交换协议

    概述

    请求和响应消息必须以开头.

    被动代理

    代理配置请求

    服务器发送 请求以提供代理配置数据. 此请求间隔ProxyConfigFrequency秒(服务器配置参数) .

    例:

    server→proxy:

    proxy→server:

    1. {
    2. "response": "success",
    3. "version": "5.4.0"
    4. }
    Proxy 请求

    proxy data 请求用于从代理获取主机接口可用性、历史、自动发现数据。此请求发送间隔 ProxyDataFrequency秒 (服务器配置参数) .

    server→proxy:

    1. {
    2. "request": "proxy data"
    3. }

    proxy→server:

    1. {
    2. "session": "12345678901234567890123456789012"
    3. "interface availability": [
    4. {
    5. "interfaceid": 1,
    6. "available": 1,
    7. "error": ""
    8. },
    9. {
    10. "interfaceid": 2,
    11. "available": 2,
    12. "error": "Get value from agent failed: cannot connect to [[127.0.0.1]:10049]: [111] Connection refused"
    13. },
    14. {
    15. "interfaceid": 3,
    16. "available": 1,
    17. "error": ""
    18. },
    19. {
    20. "interfaceid": 4,
    21. "available": 1,
    22. "error": ""
    23. }
    24. ],
    25. "history data":[
    26. {
    27. "itemid":"12345",
    28. "clock":1478609647,
    29. "ns":332510044,
    30. "value":"52956612",
    31. "id": 1
    32. },
    33. {
    34. "itemid":"12346",
    35. "clock":1478609647,
    36. "ns":330690279,
    37. "state":1,
    38. "value":"Cannot find information for this network interface in /proc/net/dev.",
    39. "id": 2
    40. }
    41. ],
    42. "discovery data":[
    43. {
    44. "clock":1478608764,
    45. "drule":2,
    46. "dcheck":3,
    47. "type":12,
    48. "ip":"10.3.0.10",
    49. "dns":"vdebian",
    50. "status":1
    51. },
    52. {
    53. "clock":1478608764,
    54. "drule":2,
    55. "dcheck":null,
    56. "type":-1,
    57. "ip":"10.3.0.10",
    58. "dns":"vdebian",
    59. "status":1
    60. }
    61. ],
    62. "auto registration":[
    63. {
    64. "clock":1478608371,
    65. "host":"Logger1",
    66. "ip":"10.3.0.1",
    67. "dns":"localhost",
    68. "port":"10050"
    69. },
    70. {
    71. "clock":1478608381,
    72. "host":"Logger2",
    73. "ip":"10.3.0.2",
    74. "dns":"localhost",
    75. "port":"10050"
    76. }
    77. ],
    78. "tasks":[
    79. {
    80. "status": 0,
    81. "parent_taskid": 10
    82. },
    83. {
    84. "type": 0,
    85. "error": "No permissions to execute task.",
    86. "parent_taskid": 20
    87. }
    88. ],
    89. "version":"5.4.0"
    90. }

    server→proxy:

    主动代理

    代理检测心跳请求

    proxy heartbeat 请求由代理发送以报告代理正在运行。 每次发送此请求间隔 HeartbeatFrequency秒 (代理配置参数)

    proxy→server:

    1. {
    2. "request": "proxy heartbeat",
    3. "host": "Proxy #12",
    4. "version": "5.4.0"
    5. }

    server→proxy:

    1. {
    2. "response": "success"
    3. }
    代理配置请求

    例:

    proxy→server:

    1. {
    2. "request": "proxy config",
    3. "host": "Proxy #12",
    4. "version":"5.4.0"
    5. }

    server→proxy:

    proxy→server:

    1. {
    2. "response": "success"
    3. }
    代理请求数据

    proxy data 请求由代理发送,以提供主机可用性,历史记录,发现和自动注册数据。 每次发送此请求 DataSenderFrequency (代理配置参数)秒。

    例:

    1. {
    2. "request": "proxy data",
    3. "host": "Proxy #12",
    4. "session": "12345678901234567890123456789012",
    5. "interface availability": [
    6. {
    7. "interfaceid": 1,
    8. "available": 1,
    9. "error": ""
    10. },
    11. {
    12. "interfaceid": 2,
    13. "available": 2,
    14. "error": "Get value from agent failed: cannot connect to [[127.0.0.1]:10049]: [111] Connection refused"
    15. },
    16. {
    17. "interfaceid": 3,
    18. "available": 1,
    19. "error": ""
    20. },
    21. {
    22. "interfaceid": 4,
    23. "available": 1,
    24. "error": ""
    25. }
    26. ],
    27. "history data":[
    28. {
    29. "itemid":"12345",
    30. "clock":1478609647,
    31. "ns":332510044,
    32. "value":"52956612",
    33. "id": 1
    34. },
    35. {
    36. "itemid":"12346",
    37. "clock":1478609647,
    38. "ns":330690279,
    39. "state":1,
    40. "value":"Cannot find information for this network interface in /proc/net/dev.",
    41. "id": 2
    42. }
    43. ],
    44. "discovery data":[
    45. {
    46. "clock":1478608764,
    47. "drule":2,
    48. "dcheck":3,
    49. "type":12,
    50. "ip":"10.3.0.10",
    51. "dns":"vdebian",
    52. "status":1
    53. },
    54. {
    55. "clock":1478608764,
    56. "drule":2,
    57. "dcheck":null,
    58. "type":-1,
    59. "ip":"10.3.0.10",
    60. "dns":"vdebian",
    61. "status":1
    62. }
    63. ],
    64. "auto registration":[
    65. {
    66. "clock":1478608371,
    67. "dns":"localhost",
    68. "port":"10050"
    69. },
    70. {
    71. "clock":1478608381,
    72. "host":"Logger2",
    73. "ip":"10.3.0.2",
    74. "dns":"localhost",
    75. "port":"10050"
    76. }
    77. ],
    78. "tasks":[
    79. {
    80. "type": 2,
    81. "clock":1478608371,
    82. "ttl": 600,
    83. "commandtype": 2,
    84. "command": "restart_service1.sh",
    85. "execute_on": 2,
    86. "port": 80,
    87. "authtype": 0,
    88. "username": "userA",
    89. "password": "password1",
    90. "publickey": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe",
    91. "privatekey": "lsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ5QCqGKukO1De7zhd",
    92. "parent_taskid": 10,
    93. "hostid": 10070
    94. },
    95. {
    96. "type": 2,
    97. "clock":1478608381,
    98. "ttl": 600,
    99. "commandtype": 1,
    100. "command": "restart_service2.sh",
    101. "execute_on": 0,
    102. "authtype": 0,
    103. "username": "",
    104. "password": "",
    105. "publickey": "",
    106. "privatekey": "",
    107. "parent_taskid": 20,
    108. "hostid": 10084
    109. }
    110. ],
    111. "tasks":[
    112. {
    113. "type": 0,
    114. "status": 0,
    115. "parent_taskid": 10
    116. },
    117. {
    118. "type": 0,
    119. "status": 1,
    120. "error": "No permissions to execute task.",
    121. "parent_taskid": 20
    122. }
    123. ],
    124. "version":"5.4.0"
    125. }

    server→proxy:

    1. {
    2. "response": "success",
    3. "tasks":[
    4. {
    5. "type": 1,
    6. "clock": 1478608371,
    7. "ttl": 600,
    8. "commandtype": 2,
    9. "command": "restart_service1.sh",
    10. "execute_on": 2,
    11. "port": 80,
    12. "authtype": 0,
    13. "username": "userA",
    14. "password": "password1",
    15. "publickey": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe",
    16. "privatekey": "lsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ5QCqGKukO1De7zhd",
    17. "parent_taskid": 10,
    18. "hostid": 10070
    19. },
    20. {
    21. "type": 1,
    22. "clock": 1478608381,
    23. "ttl": 600,
    24. "commandtype": 1,
    25. "command": "restart_service2.sh",
    26. "execute_on": 0,
    27. "authtype": 0,
    28. "username": "",
    29. "password": "",
    30. "publickey": "",
    31. "privatekey": "",
    32. "parent_taskid": 20,
    33. "hostid": 10084
    34. }
    35. }