12

私の目標:

ホストに関連付けられたグラフを.png形式で抽出したいと思います。私のGOOGLEの調査によると、このタスクを実行するように設計されたZabbixAPIはありません。そのため、Chart2.phpとCURLのユーザーにアドバイスするブログはほとんどありません。誰かが私にそれについて行く方法を説明できますか(詳細な手順)?

注:申し訳ありませんが、phpやcurlで作業したことはありません

私が試したとき

curl https://example.com/zabbix/chart2.php?graphid=1552&width=300&height=300

これを取得しましたが、リンクが機能しません

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href="/zabbix/openid?graphid=1552&amp;modauthopenid.referrer=https%3A%2F%2Fexample.com%2Fzabbix%2Fchart2.php%3Fgraphid%3D1552">here</a>.</p>
<hr>
<address>Apache/2.2.3 (Red Hat) Server at example.com Port 80</address>
</body></html>

また、これをzabbix api(JAVA)呼び出しに組み込むにはどうすればよいですか?

4

4 に答える 4

11

これは通常のパスワード認証で機能します。私が使用していないopenidに適合させる必要があり、curlで機能するようにオプションを変更する必要があります。

1. wget --save-cookies=z.coo -4 --keep-session-cookies -O - -S --post-data='name=(a zabbix username)&password=(password)&enter=Enter' 'http://example.com/zabbix/index.php?login=1'

2. wget -4 --load-cookies=z.coo -O result.png 'http://example.com/zabbix/chart2.php?graphid=410&width=1778&period=102105&stime=20121129005934'

最初のものは認証を投稿し、Cookieを保存します。2番目は同じCookieファイルをロードし、pngを取得します。

シェルを使用せずに、好みの言語とzabbixのJSON-RPC APIを使用して実装する必要があります。この言語には、すでに多くのクライアントライブラリがあります。

AFAIKですが、グラフの画像を取得するには、このようにログインする必要があります。少なくとも当面は。

編集:https ://support.zabbix.com/browse/ZBXNEXT-562が投票する(または作業を開始する)ものです

于 2012-12-01T14:13:54.040 に答える
6

上記に加えて、Zabbix 2.0を使用している場合、cURLPOSTデータがわずかに変更されています。

以下を置き換えます。

1. wget --save-cookies=z.coo -4 --keep-session-cookies -O - -S --post-data='name=(a zabbix username)&password=(password)&enter=Enter' 'http://example.com/zabbix/index.php?login=1'

次のように:

1. wget --save-cookies=z.coo -4 --keep-session-cookies -O - -S --post-data='name=(a zabbix username)&password=(password)&enter=Sign in&autologin=1&request=' 'http://example.com/zabbix/index.php?login=1'

于 2013-07-16T05:15:39.113 に答える
0

Zabbixでは、ログイン後にHTTPリダイレクトを発生させる単一のwgetコマンドで必要なデータを取得できます。

wget --post-data='name=(username)&password=(password)&enter=Enter&request=http%3A%2F%2Fexample.com%2Fzabbix%2Fchart2.php%3Fgraphid%3D410%26width%3D1778%26period%3D102105%26stime%3D20121129005934' -O (image file) 'http://example.com/index.php?login=1'

requestパラメータ値をURLエンコードすることを忘れないでください。

最新の期間が必要な場合は、stime遠い未来に設定してください。「20200101000000」は私にはうまく機能します。

Zabbix1.8.11でテスト済み。

于 2015-12-02T16:13:00.643 に答える
0

場合によっては、を使用できない、または使用したくないことがありますwget。画像をダウンロードするときにCookieを読み取って設定するためにログインハックは必要ないことがわかりました。APIを使用してログインするときに取得するZabbixセッションID(認証文字列とも呼ばれます)のみが必要です。これで、これを使用して、呼び出される1つのCookieを設定zbx_sessionidし、画像を提供するURLを呼び出すことができます。

Javaの場合:

private byte[] getPng(ZabbixUser user, URL pngUrl) throws IOException
{
  HttpURLConnection conn = (HttpURLConnection) pngUrl.openConnection();
  conn.setRequestProperty("Cookie", "zbx_sessionid=" + user.getSessionid());
  try (InputStream is = conn.getInputStream()) {
    return toByteArray(is);
  }
}


private static byte[] toByteArray(InputStream is) throws IOException
{
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  byte[] byteChunk = new byte[4096];
  int n;
  while ((n = is.read(byteChunk)) > 0) {
    baos.write(byteChunk, 0, n);
  }
  return baos.toByteArray();
}

ZabbixUserでログインしたときに得られるログイン結果を保存するために私が作成したモデルの一部です"userData": true。結果のオブジェクトには。が含まれますsessionid

于 2017-02-06T09:47:17.980 に答える