Difference between revisions of "Data export"

From Awesome Baozam
Jump to: navigation, search
(VB script)
 
(20 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Для получения данных по запросу вы можете использовать УРЛ
+
__TOC__
  
<nowiki>https://baozam.net/index.php?action=csv&hosts=<HOSTID>&period=<PERIOD_IN_SECONDS>&stime=<START_UNIXTIME>&step=<STEP></nowiki>
+
To obtain data on request you can use the URL
  
для аутентификации необходимо передать логин и пароль в ('''только''') POST.
 
  
''STIME'' - unixtime с которого '''начинается''' период. Если = 0, то начало периода будет
+
'''1''' To get data for any host items
отсчитано от текущего времени.
+
  <nowiki>https://</nowiki>baozam.net/index.php?action=csv&items='''''<ITEMID_1>,<ITEMID_2>,<...>,<ITEMID_N>'''''&period='''''<PERIOD_IN_SECONDS>'''''&stime='''''<START_UNIXTIME>'''''&step='''''<STEP>'''''
  
''STEP'' - целое число секунд. или предопределенные значения
 
# '''g1h''' - почасово
 
# '''g1d''' - по дням
 
# '''g1w''' - по неделям
 
# '''g1m''' - по месяцам
 
  
== CURL пример ==
+
'''2''' To get only pass counters data
<pre><nowiki>
+
  <nowiki>https://</nowiki>baozam.net/index.php?action=csv&hosts='''''<HOSTID>'''''&period='''''<PERIOD_IN_SECONDS>'''''&stime='''''<START_UNIXTIME>'''''&step='''''<STEP>'''''
HOST=baozam.net
+
DEVICE=
+
PERIOD=$(( 7 * 24 * 3600 ))
+
STIME=0
+
STEP=g1h
+
USER=
+
PWD=
+
  
curl "https://$HOST/index.php?action=csv&hosts=$DEVICE&period=$PERIOD&stime=$STIME&step=$STEP" \
 
    -H "Host: $HOST" --compressed \
 
    -d "name=$USER" -d "password=$PWD"
 
</nowiki></pre>
 
  
== VB script ==
+
Script should pass login and password into '''POST''' request for authentication.
<pre>
+
' This Sub downloads the FILE specified in myUrl to the file specified in mySaveTo.
+
  
Const myDevice = "<DEVICE>", myUser = "<USR>", myPwd = "<PASSWORD>"
+
''HOSTID'' - it's same id as in url of this device (Could be found on the host description page, Inventory => Hosts menu item).
Const myHost = "baozam.net", mySaveTo = "D:\baozam.csv"
+
Const myPeriod = "259200", mySTime = "0", myStep = "g1d"
+
  
HTTPDownload "https://" + myHost + "/index.php?action=csv&hosts=" + myDevice + "&period=" + myPeriod + "&stime=" + mySTime + "&step=" + myStep
+
''ITEMID_N'' - it's same id as in url of device items (The simplest way to find the id is to use ''the Latest Data'' page, Monitoring => Latest Data menu item => Select host, Filter).
Sub HTTPDownload( myUrl )
+
  
' Based on a script found on the Thai Visa forum
+
''STIME'' - unixtime of '''begin''' of period.
' http://www.thaivisa.com/forum/index.php?showtopic=21832
+
If = 0, then period begin will be calculated as difference between current time and period length.
' by Rob van der Woude
+
' http://www.robvanderwoude.com/vbstech_internet_download.php
+
  
    ' Standard housekeeping
+
''STEP'' - seconds count, or predefined values
    Dim i, objFile, objFSO, objHTTP
+
# '''g1h''' - by hours
    Const ForReading = 1, ForWriting = 2, ForAppending = 8
+
# '''g1d''' - by days
 +
# '''g1w''' - by weeks
 +
# '''g1m''' - by monthes
  
    ' Create a File System Object
+
== CURL example ==
    Set objFSO = CreateObject( "Scripting.FileSystemObject" )
+
{{Data export/curl}}
  
    ' Create or open the target file
+
== VB script ==
    Set objFile = objFSO.OpenTextFile( mySaveTo, ForWriting, True )
+
For example:
  
    ' Create an HTTP object
+
{{Data export/vbs}}
    Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )
+
  
    ' Download the specified URL
+
== OpenSSL ==
    objHTTP.Open "POST", myUrl, False
+
{{Data export/openssl}}
    'objHTTP.Option(4) = &H3300 'WinHttpRequestOption_SslErrorIgnoreFlags = 0x3300     
+
    objHTTP.setRequestHeader "myHost", myHost
+
    objHTTP.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
+
    objHTTP.Send "name=" + myUser + "&password=" + myPwd
+
  
    ' Write the downloaded byte stream to the target file
+
[[ru:Экспорт данных]]
    For i = 1 To LenB( objHTTP.ResponseBody )
+
        objFile.Write Chr( AscB( MidB( objHTTP.ResponseBody, i, 1 ) ) )
+
    Next
+
 
+
    ' Close the target file
+
    objFile.Close( )
+
End Sub
+
</pre>
+
 
+
== OpenSSL ==
+
openssl s_client -connect www.somesite:443
+
...
+

Latest revision as of 19:47, 12 June 2018

To obtain data on request you can use the URL


1 To get data for any host items

  https://baozam.net/index.php?action=csv&items=<ITEMID_1>,<ITEMID_2>,<...>,<ITEMID_N>&period=<PERIOD_IN_SECONDS>&stime=<START_UNIXTIME>&step=<STEP>


2 To get only pass counters data

  https://baozam.net/index.php?action=csv&hosts=<HOSTID>&period=<PERIOD_IN_SECONDS>&stime=<START_UNIXTIME>&step=<STEP>


Script should pass login and password into POST request for authentication.

HOSTID - it's same id as in url of this device (Could be found on the host description page, Inventory => Hosts menu item).

ITEMID_N - it's same id as in url of device items (The simplest way to find the id is to use the Latest Data page, Monitoring => Latest Data menu item => Select host, Filter).

STIME - unixtime of begin of period. If = 0, then period begin will be calculated as difference between current time and period length.

STEP - seconds count, or predefined values

  1. g1h - by hours
  2. g1d - by days
  3. g1w - by weeks
  4. g1m - by monthes

CURL example

HOST=baozam.net
DEVICE=
PERIOD=$(( 7 * 24 * 3600 ))
STIME=0
STEP=g1h
USER=
PWD=

curl "https://$HOST/index.php?action=csv&hosts=$DEVICE&period=$PERIOD&stime=$STIME&step=$STEP" \
    -H "Host: $HOST" --compressed \
    -d "name=$USER" -d "password=$PWD"

VB script

For example:

' This Sub downloads the FILE specified in myUrl to the file specified in mySaveTo.

Const myDevice = "<HOSTID>", myUser = "<USR>", myPwd = "<PASSWORD>"
Const myHost = "baozam.net", mySaveTo = "D:\baozam.csv"
Const myPeriod = "259200", mySTime = "0", myStep = "g1d"

HTTPDownload "https://" + myHost + "/index.php?action=csv&hosts=" + myDevice + "&period=" + myPeriod + "&stime=" + mySTime + "&step=" + myStep
Sub HTTPDownload( myUrl )

' Based on a script found on the Thai Visa forum
' http://www.thaivisa.com/forum/index.php?showtopic=21832
' by Rob van der Woude
' http://www.robvanderwoude.com/vbstech_internet_download.php

    ' Standard housekeeping
    Dim i, objFile, objFSO, objHTTP
    Const ForReading = 1, ForWriting = 2, ForAppending = 8

    ' Create a File System Object
    Set objFSO = CreateObject( "Scripting.FileSystemObject" )

    ' Create the target file
    Set objFile = objFSO.CreateTextFile( mySaveTo, True, True ) ' overwrite, unicode

    ' Create an HTTP object
    Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )

    ' Download the specified URL
    objHTTP.Open "POST", myUrl, False
    'objHTTP.Option(4) = &H3300 'WinHttpRequestOption_SslErrorIgnoreFlags = 0x3300      
    objHTTP.setRequestHeader "myHost", myHost
    objHTTP.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    objHTTP.Send "name=" + myUser + "&password=" + myPwd

    ' Write the downloaded byte stream to the target file
    For i = 1 To LenB( objHTTP.ResponseBody )
        objFile.Write Chr( AscB( MidB( objHTTP.ResponseBody, i, 1 ) ) )
    Next

    ' Close the target file
    objFile.Close( )
End Sub

OpenSSL

openssl s_client -connect baozam.net:443
...