Cacti (home)ForumsRepositoryDocumentation
Cacti: offical forums and support  

 FAQFAQ   SearchSearch   MemberlistMemberlist    RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in    


scripts available

 
Post new topic   Reply to topic    Cacti Forum Index -> Help: Windows Specific
Author Message
Guest






PostPosted: Tue Oct 08, 2002 12:29 pm    Post subject: scripts available Reply with quote

I've written some VBScripts to extract data from an XML file from a WeatherStation. Anybody interested ?
Back to top
mlsommer



Joined: 07 Nov 2002
Posts: 12
Location: University Center, MI

PostPosted: Tue Jan 14, 2003 8:18 am    Post subject: Yeah, I'm interested. (NM) Reply with quote

(NM)
Back to top
Guest






PostPosted: Thu Jan 23, 2003 10:31 am    Post subject: Re: Yeah, I'm interested. (NM) Reply with quote

mlsommer wrote:
(NM)

here you go:

'
'wx.vbs <param1> <param2>
'
' param1 = type of retreived value
' 1 = path style (/weather/wind/current/dirdeg)
' 2 = name style (ServerRoom)
' param2 = text to be searched for, case sensitive !
' in case of '1' :
' attn: only use one '/' at the beginning, second one will be added by this script.
' this is because scripting soes not like two '//' at the command line
' in case of '2' :
' attn: names seperated by spaced should use '_' --> 'Server Room' MUST be 'Server_Room'
' '_' will be replaced in the script by spaces again
' ..
'example:
' wx 1 /weather/wind/current/value
' wx 2 Antenne_Tower
'
'------------------------------------

On Error Resume Next

Dim oArgs, fso, oFile, MyFile, Answer, XMLValue
Dim nodeDesc, nodeTemp

Set oArgs = WScript.Arguments
If oArgs.Count <> 2 Then Wscript.Quit(0)

'
Const XmlFile = "./wx.xml"

Set fso = CreateObject ("Scripting.FileSystemObject")
If not (fso.FileExists(XmlFile)) Then
Answer = GetUrl("http://cust.93.182.adsl.cistron.nl:8880/XML")
Set MyFile = fso.CreateTextFile (XmlFile)
MyFile.Write Answer
MyFile.Close
set MyFile = Nothing
End If
Set oFile = fso.GetFile (XmlFile)
if (DateDiff("s",oFile.DateLastModified,Now)> 240)Then
Answer = GetUrl("http://cust.93.182.adsl.cistron.nl:8880/XML")
Set MyFile = fso.CreateTextFile (XmlFile)
MyFile.Write Answer
MyFile.Close
Set MyFile = Nothing
End If
Set fso = Nothing
Set oFile = Nothing

If oArgs(0) = 1 Then
XMLValue = ReadXML ("/" & oArgs(1))
Wscript.StdOut.Write XMLValue
ElseIf oArgs(0) = 2 Then
XMLValue = ReadXML2 (oArgs(1))
Wscript.StdOut.Write XMLValue
End If

wscript.quit(0)

'------------------------------------------------------------------

Function ReadXML (param)
Set objXMLDoc = CreateObject("Msxml2.DOMDocument.4.0")
objXMLDoc.async = False
objXMLDoc.load(XmlFile)
Set Node = objXMLDoc.documentElement.selectSingleNode(param)
ReadXml = Node.Text
Set objXMLDoc = Nothing
Set Node = Nothing
End Function

Function GetURL(url)
Set Retrieval = CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "GET", url, False, "", ""
.Send
GetURL = .ResponseText
End With
Set Retrieval = Nothing
End Function

Function ReadXML2 (param)
Set objXMLDoc = CreateObject("Msxml2.DOMDocument.4.0")
objXMLDoc.async = False
objXMLDoc.load(XmlFile)
objXMLDoc.setProperty "SelectionLanguage", "XPath"
Set NodeDesc = objXMLDoc.selectNodes("//weather/temperatures/temperature/description")
'grep value
Set NodeTemp = objXMLDoc.selectNodes("//weather/temperatures/temperature/current/value")
For i = 0 to (nodeDesc.length - 1)
'MsgBox param & "-" & nodeDesc.item(i).text & "-" & nodeTemp.item(i).text
If UCase(nodeDesc.item(i).text) = UCase(Replace(param,"_"," ")) Then
ReadXML2 = nodeTemp.item(i).text
Exit For
Else
ReadXML2 = "0"
End If
Next
Set ObjXMLDoc = Nothing
Set NodeDesc = Nothing
Set NodeTemp = Nothing
End Function
Back to top
mlsommer



Joined: 07 Nov 2002
Posts: 12
Location: University Center, MI

PostPosted: Fri Feb 21, 2003 6:04 pm    Post subject: Thanks! Reply with quote

Thanks!
Back to top
TFC
Guest





PostPosted: Wed Apr 09, 2003 1:58 am    Post subject: Reply with quote

How can I use this script in cacti?
how can I compile it?
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Cacti Forum Index -> Help: Windows Specific All times are GMT - 5 Hours
Page 1 of 1

 



Powered by phpBB © 2001, 2005 phpBB Group