method setHostNotes

Antworten
bobzbobz
Beiträge: 169
Registriert: 30 Nov 2012, 10:41
Wohnort: Denmark

method setHostNotes

Beitrag 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
dkoch
Beiträge: 309
Registriert: 25 Nov 2011, 14:03

Re: method setHostNotes

Beitrag 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
Zuletzt geändert von dkoch am 29 Jan 2014, 10:42, insgesamt 1-mal geändert.
bobzbobz
Beiträge: 169
Registriert: 30 Nov 2012, 10:41
Wohnort: Denmark

Re: method setHostNotes

Beitrag 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.
dkoch
Beiträge: 309
Registriert: 25 Nov 2011, 14:03

Re: method setHostNotes

Beitrag 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.
bobzbobz
Beiträge: 169
Registriert: 30 Nov 2012, 10:41
Wohnort: Denmark

Re: method setHostNotes

Beitrag 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
dkoch
Beiträge: 309
Registriert: 25 Nov 2011, 14:03

Re: method setHostNotes

Beitrag 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 "
bobzbobz
Beiträge: 169
Registriert: 30 Nov 2012, 10:41
Wohnort: Denmark

Re: method setHostNotes

Beitrag 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 :-/
dkoch
Beiträge: 309
Registriert: 25 Nov 2011, 14:03

Re: method setHostNotes

Beitrag 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.
bobzbobz
Beiträge: 169
Registriert: 30 Nov 2012, 10:41
Wohnort: Denmark

Re: method setHostNotes

Beitrag 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$" :-/
dkoch
Beiträge: 309
Registriert: 25 Nov 2011, 14:03

Re: method setHostNotes

Beitrag 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
Antworten