Seite 1 von 1

method setHostNotes

Verfasst: 29 Jan 2014, 09:08
von bobzbobz
Hi

I am currently creating a package for Teamviewer Host.
I want the host to report back the Teamviewer-ID of the client, and thought of using the "Notes"-field in OPSI-Configed for this.

I have successfully created the package and the Client-ID is written to the Notes-field by using:

Code: Alles auswählen

[Actions]
DefVar $ClientID$
Set $ClientID$ = GetRegistrystringvalue("[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\TeamViewer\Version8] ClientID")

opsiservicecall_insertNote

[opsiservicecall_insertNote]
"method": "setHostNotes"
"params": [
  "%hostId%",
  "TW ID: $ClientId$"
  ]
Now my question is:
Is there a way to append the text instead of replacing/overwriting what already is written in the Notes-field.

So the text would end up being:

Code: Alles auswählen

Notes:
Automatically created by linux bootimage
TW ID: 123456789
Instead of just:

Code: Alles auswählen

Notes
TW ID: 123456789

Re: method setHostNotes

Verfasst: 29 Jan 2014, 10:22
von dkoch
First load the current note into a variable. Then append to it and write it back.

Code: Alles auswählen

DefStringList $hosthash$
DefVar $hosthash$
DefVar $notes$
DefVar $newnotes$

Set $hosthash$ = getReturnListFromSection("opsiservicecall_gethosthash")  
set $notes$           = getValue("notes",$hosthash$)     
set $newnotes$ = $notes$ + " Something you want to append" 

[opsiservicecall_gethosthash]
"method":"getHost_hash"
"params": [
"%hostid%"                                                                                                                                                                                          
]
Then write the variable $newnotes$ back to notes. Newline could be "\n" (dont know because i have never tried that).
But remember that this will append every time you execute it. so you will have the id multiple times in it. There is also an workaround for that.

Code: Alles auswählen

if not (contains($notes$, $TeamviewerID$))
>>>Place the note writing function here<<<
endif

Re: method setHostNotes

Verfasst: 29 Jan 2014, 10:40
von bobzbobz
Sweet - I will play around with that servicecall a bit.

Is there a way to identify the excact line "TW ID: XXXXXXXXX" from the notes and replace it with the new TW ID - lets say i want to reinstall (win7) a client which already has Teamviewer installed.

Re: method setHostNotes

Verfasst: 29 Jan 2014, 10:45
von dkoch
sed can do what you want

http://gnuwin32.sourceforge.net/packages/sed.htm

Code: Alles auswählen

[DosInAnIcon]
echo $newnotes$ | sed.exe "s/TW ID\: [a-zA-Z0-9]*//g"
echo fooo fooo fooo TW ID: Something bar bar bar | sed 's/TW ID\: [a-zA-Z0-9]*//g'
Results in:
fooo fooo fooo bar bar bar
Should remove "TW ID: SOMETHING" from any string ( not tested ). You can use getOutStreamFromSection to get it back to another variable.

Re: method setHostNotes

Verfasst: 29 Jan 2014, 11:22
von bobzbobz
Yea - this seems to work ;)

I downloaded sed binaries+dependencies and ran your command from my own PC which outputs the text you said (just had to change ' -> ").
I will experiment with my Teamviewer-package and post back the result here + upload scripts to wiki.

Thanks

Re: method setHostNotes

Verfasst: 29 Jan 2014, 11:38
von dkoch
bobzbobz hat geschrieben:Yea - this seems to work ;)

I downloaded sed binaries+dependencies and ran your command from my own PC which outputs the text you said (just had to change ' -> ").
I will experiment with my Teamviewer-package and post back the result here + upload scripts to wiki.

Thanks
Yes for GNU/Linux ' is used. For Windows its "

Re: method setHostNotes

Verfasst: 29 Jan 2014, 11:57
von bobzbobz
Another question ;)

1. First I get "Notes" from the $hosthash$.
2. Then I edit out the "TW ID: XXXXXXXXX".
3. Then I use GetOutStreamFromSection to get the output.

This returns a list (DefStringList) which I want to pair with the $ClientID$ and then return the notes via servicecall.

How do i excactly do this?

Right now my code is:

Code: Alles auswählen

Set $ClientID$ = GetRegistrystringvalue("[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\TeamViewer\Version8] ClientID")
Set $newnotes$ = $sednotes$ + " /n " + "Teamviewer-ID: $ClientID$"
($sednotes$ is the result from sed.exe - which is a DefStringList).

which doesnt work :-/

Re: method setHostNotes

Verfasst: 29 Jan 2014, 12:18
von dkoch
Yes sednotes should be a StringList. Use takeString to get a String out of that StringList. Lookup the Index of the output in your instlog.
You'll probably use getOutStreamFromSection to fill $sednotesstream$ and use takeString(X,$sednotesstream$) to fill $sednotes$. That must be done because you cant use StringLists as Strings for obvious reasons.
Here is an example from a logfile:

Code: Alles auswählen

[6] [Jan 29 11:46:26:717] [set_ip]     retrieving strings from getOutStreamFromSection [switch to loglevel 7 for debugging]
[7] [Jan 29 11:46:26:717] [set_ip]         (string   0)
[7] [Jan 29 11:46:26:717] [set_ip]         (string   1)C:\Windows\system32>wmic computersystem get model 
[7] [Jan 29 11:46:26:717] [set_ip]         (string   2)Model          
[7] [Jan 29 11:46:26:717] [set_ip]         (string   3)
[7] [Jan 29 11:46:26:717] [set_ip]         (string   4)OptiPlex 7010  
[7] [Jan 29 11:46:26:717] [set_ip]         (string   5)
[7] [Jan 29 11:46:26:717] [set_ip]         (string   6)
[7] [Jan 29 11:46:26:717] [set_ip]         (string   7)
[7] [Jan 29 11:46:26:717] [set_ip]         
[5] [Jan 29 11:46:26:717] [set_ip] 
[5] [Jan 29 11:46:26:717] [set_ip] Set  $Model$ = takeString(4,$ModelStream$)
[6] [Jan 29 11:46:26:719] [set_ip]     retrieving strings from $ModelStream$ [switch to loglevel 7 for debugging]
[7] [Jan 29 11:46:26:719] [set_ip]         (string   0)
[7] [Jan 29 11:46:26:719] [set_ip]         (string   1)C:\Windows\system32>wmic computersystem get model 
[7] [Jan 29 11:46:26:719] [set_ip]         (string   2)Model          
[7] [Jan 29 11:46:26:719] [set_ip]         (string   3)
[7] [Jan 29 11:46:26:719] [set_ip]         (string   4)OptiPlex 7010  
[7] [Jan 29 11:46:26:719] [set_ip]         (string   5)
[7] [Jan 29 11:46:26:719] [set_ip]         (string   6)
[7] [Jan 29 11:46:26:719] [set_ip]         (string   7)
[7] [Jan 29 11:46:26:719] [set_ip]         
[6] [Jan 29 11:46:26:719] [set_ip]   The value of the variable "$Model$" is now: "OptiPlex 7010  "
I am taking String 4 of $ModelStream$ and store it into $Model$ here.

Re: method setHostNotes

Verfasst: 29 Jan 2014, 13:23
von bobzbobz
Hmm - I found that if I have line breaks in my Notes-field then the DosInAnIcon-section for sed.exe will fail:

Setup-script:

Code: Alles auswählen

...
Set $hosthash$ 		= getReturnListFromSection("opsiservicecall_gethosthash")
Set $notes$           	= getValue("notes",$hosthash$)
...
[DosInAnIcon_removeid]
echo $notes$ | %ScriptPath%\sed\sed.exe "s/Teamviewer-ID\: [a-zA-Z0-9]*//g"
Notes-field (OPSI-configed):

Code: Alles auswählen

Notes:
this is a test


blah blah blah
Log-file after install:

Code: Alles auswählen

C:\Windows\system32>echo this is a test
this is a test

C:\Windows\system32>blah blah blah   | P:\teamviewerhost\sed\sed.exe "s/Teamviewer-ID\: [a-zA-Z0-9]*//g" 
'blah' was not recignized as an internal or external command,
a program, or a batchfile.
If I take a look in my OPSI-configed afterwards, the Notes-field says "$newnotes$" :-/

Re: method setHostNotes

Verfasst: 29 Jan 2014, 13:38
von dkoch
Well Dos is ugly. Lets try another hack:

- Store $notes$ in a file using PatchTextFile
- run sed on it : %ScriptPath%\sed\sed.exe -i "s/Teamviewer-ID\: [a-zA-Z0-9]*//g" $TEXTFILE$
- Load it into a StringList with loadTextFile
- Use composeString to covert the StringList to a string. You may use "\n" as LinkString to get the line breaks back ( if \n is the newline, i dont know)
- Store the composedString as note